Vuex learning summary

Vuex overview

Vuex is a mechanism to implement global state (data) management of components and facilitate data sharing among components

Benefits of using Vuex to manage data: A. Centralized management of shared data in Vuex facilitates development and maintenance B. C. The data stored in VUEX is responsive. When the data changes, the data on the page will be updated synchronously

State

State provides the only common data source, and all shared data is stored in State in the Store

Mutation

Mutation is used to modify data in the $store

Do not execute an asynchronous function in the mutations function

Action

Action is used to process asynchronous tasks

If the data is changed by an asynchronous operation, it must be changed through an Action rather than Mutation, but the data must be changed indirectly by triggering Mutation in the Action.

In actions, you cannot directly modify data in state; A mutation must be triggered by context.mit ()

An parameter is taken when an Actions asynchronous task is triggered

Getter

Getters are used to process data in a Store to form new data.

  1. Getters can process existing data in the Store to form new data, similar to the calculation properties of Wue.
  2. As the data in the Store changes, so does the data in the Getter.