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

问题描述 投票:1回答:1

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

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})

我可以发送品牌但需要立即发送整个数据阵列

vue.js axios
1个回答
3
投票

要获得整个data对象,你必须使用this.$data

updated: function () {
   axios.post('http://localhost:81/lnt/public/member/car_result', {data: this.$data})
   .then(function (response) {
       //do something
    });
}
© www.soinside.com 2019 - 2024. All rights reserved.