vuex mutation, action understanding

1. Register mutation and action in the store respectively. In action, commit is used to call mutation synchronously to modify the state, but in the component, dispatch is used to call action asynchronously.

2. In layman's terms, vuex is designed with the core business of communication.

Among them, state is the global data source, which supports multi-component two-way binding.

To change the state anywhere you need to go through the commit store mutation.

But mutation only supports synchronous operations.

To complete an asynchronous operation, such as communicating with the backend and then assigning data to the state, you need to go to the commit store's mutation through the asynchronous callback of the action.

That is to say, if you want to use asynchronous, you must use action, and if you want to use action, you must use mutation, which is itself a process of data change.

The component uses this.$store.dispatch('XXXX') to call the action, and the syntactic sugar actionMap can be used to map and bind multiple actions.

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326220240&siteId=291194637