我需要通过 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) {
});
}
});
Run Code Online (Sandbox Code Playgroud)
当我console.log(this.data);得到一个未定义的输出 当我尝试
axios.post('http://localhost:81/lnt/public/member/car_result', {brand: this.brand})
Run Code Online (Sandbox Code Playgroud)
我可以发送品牌但需要一次发送整个数据阵列
要获得整个data对象,您必须使用this.$data
updated: function () {
axios.post('http://localhost:81/lnt/public/member/car_result', {data: this.$data})
.then(function (response) {
//do something
});
}
Run Code Online (Sandbox Code Playgroud)