Last active
November 12, 2021 09:30
-
-
Save egoson/0eb003e3a2b16e6758249d8cb037fe22 to your computer and use it in GitHub Desktop.
event handler for vuex module
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
| // mutationTypes.js | |
| export default { | |
| setUser: '[USER] Set User', | |
| removeUser: '[USER] Remove User' | |
| } | |
| // userModule.js | |
| import mutationTypes form './mutationTypes' | |
| export default { | |
| mutations: { | |
| [mutationTypes.setUser](state, payload) { | |
| state.user = payload | |
| } | |
| } | |
| } | |
| // mutationHandler.js | |
| export default (module) => { | |
| return (store) => { | |
| store.subscribe((mutation, store) => { | |
| if (mutation.type.startsWith(module)) { | |
| **do somethings** | |
| } else { | |
| } | |
| }) | |
| } | |
| } | |
| // index.js | |
| ... | |
| plugins: [ | |
| mutationHandler(['[USER]']), | |
| ], |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment