码迷,mamicode.com
首页 > 移动开发 > 详细

vue请求方式axios和axios.get

时间:2017-11-09 11:26:02      阅读:210      评论:0      收藏:0      [点我收藏+]

标签:vue   axios   axios.get   

    <!DOCTYPE html>
    <html>
        <head>
            <meta charset="utf-8" />
            <title>axios</title>
        </head>
        <script type="text/javascript" src="js/vue.js" ></script>
        <script type="text/javascript" src="js/axios.min.js" ></script>

        <script>
            window.onload = function(){
                //配置是否允许检查代码,方便调试,生产环境中设置为false
                Vue.config.devtools = true;  //检查代码
                Vue.config.productioinTip = false;  //有强迫症的,可以关掉生产中的提示信息
                new Vue({
                    el:‘#div1‘,
                    methods:{
                        send(){
                            axios({
                                method:‘get‘,
                                url:‘user.json‘
                            }).then(function(res){
                                console.log(res.data);
                            }).catch(function(msg){
                                console.log(msg.status);
                            });
                        },
                        getSend(){
                            axios.get(‘user.php‘,{
                                params:{
                                    name: ‘李四‘,
                                    age: 19
                                }
                            }).then(res => {
                                console.log(res.data);
                            }).catch(err => {
                                console.log(‘get请求失败:‘+err.status+‘,‘+err.statusText);
                            })
                        }
                    }
                })
            }
        </script>
        <body>
            <div id="div1">
                <button @click="send">axios请求</button>
                <button @click="getSend">get请求</button>
            </div>
        </body>
    </html>
<?php
    $name = $_GET[‘name‘];
    $age = $_GET[‘age‘];
    $msg =  ‘用户名:‘.$name.‘,年龄:‘.$age;
    echo $msg;


本文出自 “Note” 博客,转载请与作者联系!

vue请求方式axios和axios.get

标签:vue   axios   axios.get   

原文地址:http://3miao.blog.51cto.com/9661385/1980138

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!