After clicking a button, I trigger a vuex action which returns an axios promise from the store. In my component, I only want to reset form fields when the action is successful. However, currently the form fields are always reset, even if the promise fails. I am using "then" and "catch" for this purpose, with the resetForm method being called in the "then" resolve block. Unfortunately, it resets regardless of the outcome...
Below is the code snippet from my component:
const self = this;
this.sendContactMail(payload)
.then((response) => {
// This always triggers, irrespective of promise success
self.resetData();
},
(error) => {
});
And here is my vuex action code:
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 });
});
}