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
The previous article introduced several methods f...
Date type differences and uses MySQL has five dat...
1. Enter the configuration file of the yum source...
Table of contents Why use setState Usage of setSt...
Table of contents Preface Using websocket Constru...
This article shares the specific code of Vue to a...
The filter attribute defines the visual effect of...
Today, when I was building a redis environment in...
By default, Flash will always be displayed at the ...
This article example shares the specific code of ...
Preface After deploying the server, I visited my ...
There are many ways to generate a global ID. Here...
1. Create a table CREATE TABLE `student` ( `id` i...
When using MySQL, dates are generally stored in f...
Cluster Deployment Overview 172.22.12.20 172.22.1...