Created
September 20, 2019 12:18
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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