Ajax的post请求

<!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">
        <button @click = "postdata">请求</button>
    </div>
</body>
    <script>
        new Vue({
            el: '#app',
            methods:{
                postdata:function(){
                    // 1请求的url
                    var url = 'http://vueapi.ittun.com/api/addprodlist';
                    //2.0 利用vue-resource发出ajax的get请求
                    this.$http.post(url,{name:'小狮子'},{emulateJSON:true})//发出请求
                        .then(function(response){
                           alert(response.body.message);
                        });

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

猜你喜欢

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