I have an action which fires on form submit in component
this.$store.dispatch('registerAction', this.registerData);
Also in this component I want to show message like "Registration is successful".
For that I want to listen for property in my this.$store.state
registerSuccess
which is false by default.
registerAction (Vuex)
return this.api.registerUser()
.then(response => {
if(response.success) {
return store.dispatch('registerSuccess');
}
return store.dispatch('registerFail');
});
registerSuccess
mutation sets state.registerSuccess = true;
(and fail sets it to false)
Question:
How can I listen for changes to state.registerSuccess
in this case? If I'm putting it in computed it returns false. Although it does change in Vuex store to true
computed: {
registerSuccess() {
console.log(this.$store.state.registerSuccess)
return this.$store.state.registerSuccess;
}
},