How to call the Mutations from inside the different Modules in Vuejs?

When we implement dynamic modules in the Vue app, sometime we'd like to call the mutations from inside the different modules. We have to add root option to be true when we run each commit action.

Call a mutation of the Root module from another module:

 commit('rootMutation', payload, { root: true });

Call a mutation from the different modules (use namespaced):

 commit('moduleName/moduleMutation', payload, { root: true })

Explaining: root = true make the scope of the commit run on top level of the store (Root of the store). From there, we can see and run all of mutations that we have implemented before.

© 2019 4codev

Created with love by Sil.