Vuejs data is two-way bound, and the data is only in the parent component, if the data common to each component is to be managed through a container.
Vuex is a good choice,
Today, I looked at the next Vuex tutorial:
Summary of the problems encountered: VUE-CLI a project
Import when the error was found: node version is too low, the upgrade version is good.
Import {Mapstate,mapactions,mapgetters,map} from "Vuex";//note curly braces. Https://github.com/lin-xin/notepad/This example is very good. Combined with the concept of modules Vuex core
Five core attributes:
- State
- Getters
- Mutations
- Actions
- Modules
Four auxiliary functions
- Mapstate
- Mapgetters
- Mapactions
- Mapmutations
Run the process
State is the data storage warehouse, can be divided into Submodule module, each module has a self-supporting contextual object context, has its own state, mutation, action, getters, modules and so on system
Getters is primarily used to obtain data from the state, with the advantage of being versatile
Mutations is used to update the data in the state repository, the only change data place, real-time synchronization modification, not asynchronous, not asynchronous, not asynchronous
Actions mainly supplement the ability to update the state warehouse data asynchronously, and the internal still triggers the mutation to implement
Modules to manage the Data warehouse in order to partition the state module
Note: getters,mutations,actions is mounted directly on the instance store of Vuex, either in the module block, only the state maintains a chained namespace, for example, Store.state.module[key] And so on, so if the state of the submodule, directly with the auxiliary function mapstate is not obtained.
Vuejs + Vuex