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
This article example shares the specific code of ...
After installing Jenkins, the initial download of...
Table of contents 1. Constraint concepts and clas...
If Ubuntu is the most popular Linux operating sys...
Preface This article mainly introduces 4 methods ...
This article mainly introduces the deployment of ...
MySQL is a very powerful relational database. How...
This article example shares the specific code of ...
Table of contents for loop While Loop do-while lo...
Table of contents 1. Project Description: 2. Proj...
Introduction Memcached is a distributed caching s...
Code implementation: Copy code The code is as fol...
Character set error always exists locale: Cannot ...
Let's start with a description of the problem...
motivation Due to learning needs, I purchased a v...