If you have used vue.js before, you must know the pain of passing values between components in vue. In vue, we can use vuex to save the state we need to manage. Value, let's take a look at some commonly used knowledge points in vuex, I hope it will be helpful to everyone.
1. Why use Vuex
1. Multiple components rely on the same state, and using communication methods between components will be very cumbersome, such as multi-layer nested components. .
2. Data that needs to be saved globally, such as user, permission information, global system settings
2. Five core attributes of Vuex
1 , state: storage state
1 2 3 4 |
|
2. getters: state is used as the first parameter, and other getters are used as the second parameter. The return value will be cached according to its dependencies, which is equivalent to Vue’s calculated properties
1 2 3 4 5 6 7 8 9 10 |
|
3. Mutations: Modify the state (synchronous), state as the first parameter, submit the payload as the second parameter
1 2 3 4 5 6 7 8 9 |
|
4. Actions: Asynchronous operations (methods for executing mutations, not direct Change status)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
|
5. modules: submodule of store
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
|
3. Vuex auxiliary function
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
|
Related recommendations:
2020 Summary of front-end vue interview questions (with answers)
vue tutorial recommendation: The latest 5 vue.js video tutorials in 2020 Select
For more programming-related knowledge, please visit:Introduction to Programming! !
The above is the detailed content of Common knowledge points in Vuex (summary). For more information, please follow other related articles on the PHP Chinese website!