vue: base: vuex

0. Data will be lost when vuex is refreshed, how to achieve permanent storage?

(1) Store locally

(2) Use the vuex-persist plug-in to generate for vuex, no need to manually obtain storage, and store it directly in localStorage or cookie.

1. What is the process of Vuex?

        Vuex is a solution to Vue state management, centralized storage

2. What scenarios is vuex suitable for?

        Suitable for multi-component data sharing and passing data across components

3. What is the process of vuex?

        The page submits the request to the action asynchronously through mapAction, and the action submits the parameters to the mutation synchronously through commit, and the mutation puts the modified value into the state, and throws the value out through the getter, and the page gets the state value through the mapGetter in the computed.

4. What are the features of vuex? What are the functions? 【5 features】

        The five features are: state, getter, mutation, action, module( mapAction)

        (1) state: used to store variables.

        (2) getter: It can be understood as a calculated property.

        (3) mutation: The method of submitting data can only perform synchronous operations.

        (4) action: Similar to the mutation function, you can access the methods in the mutation.

                Differences: 1. Asynchronous operations can be performed 2. The submitted mutation cannot directly modify the state;

        (5) module: Modular vue, so that each module can have its own state, getter, mutation, action.

5. What is the difference between Action and mutation in vuex?

        Mutations are similar to events. Each mutation has its own type and callback method. The callback method is used to store the value of state, and the default state is the first parameter. It only supports synchronization and is a method of submitting data.

        Action can support asynchronous operation, and the submitted mutation cannot directly change the state.

        Note) The only way to change state in vuex is mutation.

6. How does vuex store state? There are two ways

        (1) dispatch: used when asynchronous, using method: this.$store.dispatch({'action method', value})

        (2) commit: used during synchronization, using method: this.$store.commit({'mutation method', value})

7. Is axios in vue written in action or methods?

In two cases

        1. If there is only request data, it does not need to be in action.

        2. If multiple components reuse data, put it in action. That is, when reusing, in the action, it is packaged as a promise and returned, and async await is used to process the data.

8. How does vuex judge whether the current state is modified externally or through mutation?

        The only way to modify the state in vuex is to commit. The bottom layer is to set the Commiting variable to true through this.withCommit, and then the state can be modified. After the modification, the variable will be restored. The Commiting logo cannot be modified externally; watch is required to monitor the state. When stateChange judges whether this variable is true, you will know the legality of the modification.

Guess you like

Origin blog.csdn.net/u013592575/article/details/126703252