How can I mutate my module store state using map mutations from a ... | vue mutation map
Ihaveamodulecalled“moduleA”anditsstatecontains“errorMessage”andamutationcalled“storeErrorMessage”.TheerrormessagerendersinmycomponentcorrectlybuttheproblemisthatIamunabletoclearitbeforeleavingtheroute.IhaveamutationmethodinthemoduleAcalled“clearErrorMessage”whichissupposedtosetthemoduleAerrorMessagestatetonullbutitdoesnotworkthatway.Seebelowsomeofmycodes://InmoduleAconststate={errorMessage:“”,okMessage:“”}constmutations={storeErrorMessage(state,error){state.errorMessage=error},storeOkMessage...
I have a module called “moduleA” and its state contains “errorMessage” and a mutation called “storeErrorMessage”. The error message renders in my component correctly but the problem is that I am unable to clear it before leaving the route. I have a mutation method in the moduleA called “clearErrorMessage” which is supposed to set the moduleA errorMessage state to null but it does not work that way.
See below some of my codes://In moduleAconst state = {errorMessage: “”,okMessage: “”}
const mutations = {storeErrorMessage(state, error) {state.errorMessage = error},storeOkMessage(state, okMessage) {state.okMessage = okMessage},clearOkMessage(state) {state.okMessage = null},clearErrorMessage(state) {state.errorMessage = null}}
//In my componentmethods: {…mapMutations(“moduleA”, [“clearErrorMessage”]),…mapMutations(“moduleA”, [“clearOkMessage”])},
beforeRouteLeave: (to, from, next) => {this.clearErrorMessage;this.clearOkMessagenext();}
I don’...