使用axios将vue.js数据对象发送到后端

时间:2018-12-11 13:25:37

标签: vue.js axios

我需要通过axios将Vue实例的完整数据对象发送到后端。这是我的代码。

var vm = new Vue({
    el: '#el',
    delimiters: ["[[", "]]"],
    data: {
        brand: 0,
        model: 0,
        country: "europe",
    },
    created: function () {
    },
    updated: function () {
        axios.post('http://localhost:81/lnt/public/member/car_result', {data: this.data})
            .then(function (response) {

        });
    }
});

当我console.log(this.data);收到未定义的输出时 当我尝试

axios.post('http://localhost:81/lnt/public/member/car_result', {brand: this.brand})

我可以发送品牌,但需要一次发送整个数据数组

1 个答案:

答案 0 :(得分:3)

要获取整个data对象,您必须使用this.$data

updated: function () {
   axios.post('http://localhost:81/lnt/public/member/car_result', {data: this.$data})
   .then(function (response) {
       //do something
    });
}
相关问题