Vuex-getters、modules

1. There are more and more states in vuex, which will cause the store to become more and more bloated. We can use modules to divide our corresponding data resources into modules.
2. Module has its own independent state, mutations, actions, getters, modules
3. How to obtain the state in the module:

data name in this.$store.state.module name.state

4. How to obtain getters

this.$store.getters.modulename.name in getters

5. The module must add namespaced: truethis configuration!!!, so that the mutation and action in the module can automatically add the module name as a prefix to form a new name.

Module name/mutation name
Module name/action name

6. If you submit the mutation in the module or the action in the distribution module in the component, you must add the prefix

this.$store.commit("module name/mutation name")

this.$store.dispatch("module name/action name")

7. If it is submitted in action, the submission is the mutation in the current module, no need to write the prefix

commit(“mutation last name”)

8. How to submit mutations in external modules or globals?

commit('module name/mutation name', data, {root: true})

9. The division of modules is based on data

Guess you like

Origin blog.csdn.net/m0_56232007/article/details/118708071