1.VueX state management mechanism refers to the establishment of a “warehouse”, and all components get the value of the “warehouse” without affecting each other.
2.1) Create a store.js file and import it in main.js
2) State defined value:
Use $store.state.num to get the worth component
3) Getters get values: Define getters in store and declare a method to get values.
And then you want to get data for computed write in the value component, and I’m going to write getNum here
You can get it at this point. However, this method is not recommended, as detailed in the use of mapGetters below
4) Mutations: synchronously operate the data in state. Mutations are defined in store, and num+1 is applied via the addNum method
In the component to operate on, define a button to perform the +1 operation
Write it in the add method, commit it in mutations, and the parameters are defined in mutations
Mutations transfer: Define a data after the parameters
But also on mutations
5) Actions: Asynchronously operate data in state. This author recommends an Actions approach when working with data. Actions is similar to mutations, which modify data through asynchronous callbacks. Start by declaring actions in the store, addByNumAction is the method defined in Actions, ‘addA’ in the parameter is the method defined in mutations, and data passes the parameter
A method is then declared in the component to be operated on and submitted via Dispatch
6) MapGetter gets data defined in getters and is first declared in getters
Mapgetters must be declared by importing Mapgetters from ‘vuex’
After listening in comptued, you can use it