【问题标题】:send vue.js data object to backend using axios使用 axios 将 vue.js 数据对象发送到后端
【发布时间】:2018-12-11 13:25:37
【问题描述】:

我需要通过 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})

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

【问题讨论】:

  • 好的,所以,不要使用{data: this.data},而是使用this.data...应该可以解决问题:)

标签: vue.js axios


【解决方案1】:

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

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

【讨论】:

  • 非常感谢兄弟拯救了我的一天
  • 没问题 - 我很高兴能帮上忙 :-)
猜你喜欢
  • 2021-11-16
  • 2018-06-20
  • 1970-01-01
  • 2019-06-20
  • 2021-06-06
  • 2020-06-16
  • 1970-01-01
  • 2021-03-24
  • 2021-08-14
相关资源
最近更新 更多