【发布时间】:2020-07-07 18:31:41
【问题描述】:
当我单击一个按钮时,我触发了一个 vuex 操作,此操作从 vuex 商店返回一个 axios 承诺,在我的组件中,我只想在操作成功时重置表单文件,但是现在它总是重置表单文件,即使如果承诺失败......我正在使用 then 并 catch 来实现这个目的,在 then 解析中触发 resetForm 方法,遗憾的是无论如何它总是会重置......
这是我的组件中的代码:
const self = this;
this.sendContactMail(payload)
.then((response) => {
//This always fires, even if promise fails
self.resetData();
},
(error) => {
});
我的 vuex 操作:
sendContactMail({ commit }, payload)
{
commit('Loader/SET_LOADER', { status:1 }, { root: true });
return axios.post('/api/contacts/send-contact-mail', payload)
.then((response) => {
commit('Loader/SET_LOADER', { status:2, response: response }, { root: true });
},
(error) => {
commit('Loader/SET_LOADER', { status:3, errors: error }, { root: true });
});
}
【问题讨论】:
标签: javascript vue.js