vue resource 发送异步请求

    <!DOCTYPE html>
    <html>
    <head>
        <script src="../vue2.4.4.js"><script>
        <script src="../vue-resource.js"></script>
    </head>
    <body>
        <div id="app">
            {{ name }}
        </div>
    <script>
            new Vue({
                el:"#app",
                data:{
                    name;" "
                 },
                 methods: {

                },
                created: function(){
                    //发送请求到服务器加载数据
                    //vue-resources 发送get请求
                    /* this.$http.get("http://www.cnblogs.com/api/getprodlist").then(function(result) {
                            var res = result.body;
                            this.name = res.message[0].name;
                        }); */
                    //vue-resource 发送post 请求
                        this.$http.post("http://www.cnblogs.com/api/addproduct",{"name":"小明"}).then(function(result) {
                                var res = result.body;
                                alert(res.message);
                        });
                }

            })
     </script>
</html>
posted @ 2018-03-15 15:47  haha瓜  阅读(106)  评论(0编辑  收藏  举报