vue-resource 实现Ajax的get请求

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="vue.js"></script>
    <script src="vue-resource.js"></script>
</head>
<body>
    <div id="app">
        {{ obj | json }}
        <button @click = "getdata">请求</button>
    </div>
</body>
    <script>
        new Vue({
            el: '#app',
            data:{
                obj:null
            },
            methods:{
                getdata:function(){
                    //1请求的url
                    var url = 'http://vueapi.ittun.com/api/getprodlist';
                    //2.0 利用vue-resource发出ajax的get请求
                    this.$http.get(url)//发出请求
                        .then(function(response){
                            response.body//获取到响应回来的数据
                        });

                }
            }
        });
    </script>
</html>

猜你喜欢

转载自blog.csdn.net/weixin_42124866/article/details/81099568