【发布时间】:2018-09-29 18:18:52
【问题描述】:
我试图将来自 api 调用的错误消息放入 vuex 存储中,但我不知道该怎么做。
我在 vue 文件中的“方法”中有这个
axios
.post("/api/model", this.model)
.then(response => {
window.location.href = "/Home/Index";
})
.catch(function(error) {
if (error.response) {
this.$store.commit("setServerErrors", error.response.data);
}
});
我收到以下错误: Uncaught (in promise) TypeError: Cannot read property '$store' of undefined
【问题讨论】:
-
将函数更改为箭头,您将失去
this范围