Vuex is a state management pattern developed specifically for Vue.js applications. It uses centralized storage to manage the status of all components of an application and uses corresponding rules to ensure that the status changes in a predictable manner. Vuex is also integrated into Vue's official debugging tool devtools, providing advanced debugging features such as zero-configuration time-travel debugging, state snapshot import and export, etc. 1. State
import { computed } from 'vue' import { useStore } from 'vuex' export default { setup () { const store = useStore() return { count: computed(() => store.state.count) } } } Getters
import { computed } from 'vue' import { useStore } from 'vuex' export default { setup () { const store = useStore() return { double: computed(() => store.getters.double) } } } Mutations
const store = createStore({ state: { count: 1 }, mutations: increment(state) { state.count++ } } })
store.commit('increment') Actions
const store = new Vuex.Store({ state: { count: 0 }, mutations: increment(state) { state.count++ } }, actions: { increment(context) { context.commit('increment') } } }) Action is triggered by store.dispatch method: store.dispatch('increment') Modules
const moduleA = { state: () => ({ ... }), mutations: { ... }, actions: { ... }, getters: { ... } } const moduleB = { state: () => ({ ... }), mutations: { ... }, actions: { ... } } const store = createStore({ modules: a: moduleA, b: moduleB } }) 6. vuex-persistedstate
1. Installation npm install --save vuex-persistedstate 2. Use import Vuex from "vuex"; import createPersistedState from "vuex-persistedstate"; const store = new Vuex.Store({ plugins: [createPersistedState()], }); The above is the details of how to quickly get started with Vuex state management in Vue3.0. For more information about Vuex state management, please pay attention to other related articles on 123WORDPRESS.COM! You may also be interested in:
|
<<: How to install PostgreSQL and PostGIS using yum on CentOS7
>>: How to completely uninstall mysql under CentOS
Preface In our daily work, we often need to renam...
<body> <div id="root"> <...
usemap is an attribute of the <img> tag, use...
Solve the problem that the vue project can be pac...
First, download the green free installation versi...
You can save this logo locally as a .rar file and...
Adding necessary comments is a good habit that a ...
Table of contents one. environment two. Precautio...
1. Introduction to VMware vSphere VMware vSphere ...
This article uses examples to illustrate the tabl...
Below is the code that Shiji Tiancheng uses to ca...
Note: You cannot use scoped animations! ! ! ! via...
1. Install SVN server yum install subversion 2. C...
One sentence to introduce HOC What is a higher-or...
mysql master-slave configuration 1. Preparation H...