在 axios 请求后的处理,需要先将 VUE 的 this 对象保存起来,不能直接在axios里用this对象
let _this;
let vm = new Vue({
el: "#app",
data: {
deleted: false,
},
beforeMount: function () {
_this = this;
},
methods: {
del(id) {
// 使用拼接进行删除
axios.delete("/del?id=" + id).then(function (res) {
console.log(res.data);
_this.deleted = true; // 不能直接使用 this
}).catch(function (err) {
console.log(err);
});
},
}
});