A Vuex.


Vuex is composed of five parts, the state respectively, getters, mutations, actions, and modules. Here they are in turn:

1.state

The global data in each component is placed in store to facilitate data acquisition in the later stage. The only way to modify a store in vuEX is to commit a mutationCopy the code

2.getters

Computations used uniformly in various components are used in getters in VUEX to reduce code redundancy.

3.mutations

Mutation is the only way to change the state in vuex's store. In addition, it is an important rule that mutation must be a synchronous function, not an asynchronous one.Copy the code

4.actions

Is specifically designed to deal with asynchronous problems. The actual revision of the state in the store is still mutations.Copy the code

5.modules

Store can be thought of as a main module, like the user module can be written under the Store module, At the same time the user module can have state. Js, getters, js, actions. Js, mutations, js, index. The index of js files in the user module. The js file must have the namespace, namely ` ` ` js namespaced: true, ```Copy the code
  1. Helper method
Write in computed: mapStates(['Name']) mapGetters(['Name']) in methods: mapMutations(['Name']) mapActions(['Name'])Copy the code

Corresponding demo case address: gitee.com/xu_xia_ke/v…