Skip to content

Instantly share code, notes, and snippets.

@ezirmusitua
Created September 20, 2019 12:18
Show Gist options
  • Save ezirmusitua/ae9f5db4bc550e2350757a932a27d754 to your computer and use it in GitHub Desktop.
Save ezirmusitua/ae9f5db4bc550e2350757a932a27d754 to your computer and use it in GitHub Desktop.
Use root action [Use root action with module dispatch in vuex] #vue #javascript
// stores.js
const moduleA = {
state: {},
mutations: {},
actions: {
action2({dispatch) {
dispatch('action1', null, {root: true}); // add {root:true} in dispatch method
}
},
getters: {}
}
const store = new Vuex.Store({
modules: {
a: moduleA,
b: moduleB
},
actions: {
action1() {
// actions1 in root actions
}
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment