Home >Web Front-end >JS Tutorial >Detailed explanation of vuex usage steps
This time I will bring you a detailed explanation of the steps to use vuex, and what are the precautions when using vuex. The following is a practical case, let's take a look.
vuex is a centralized state management architecture specially designed for vue.js. state? I understand it as the property in the data that needs to be shared with other vue components, which is called state. Simply put, it is the attributes that need to be shared in data.
1. In the vue component
execute the enabledcheckbox method, true is the parameter, used to change the value in state
this.$store.dispatch("enabledcheckbox",true)
Get the value of useredit from state
this.$store.state.useredit
2 Add the value to the object exported by vuex to state
Add mutations to change the value of state
Addactions to mutations
import Vue from 'vue' import vuex from 'vuex' Vue.use(vuex) export default new vuex.Store({ state: { useredit: false, }, mutations: { ENABLEDCHECKBOX(state, value) { state.checkboxDisable = value }, }, actions: { enabledcheckbox({ commit }, value) { commit('ENABLEDCHECKBOX', value) }, } }) //console.log(vuex)
In main.js
import store from './vuex' new Vue({ el: '#app', router, store, render:h=>h(App) })
I believe you have mastered it after reading the case in this article For more exciting methods, please pay attention to other related articles on the php Chinese website!
Recommended reading:
vue axios implements data interaction
Detailed explanation of practical skills of Angular Component
The above is the detailed content of Detailed explanation of vuex usage steps. For more information, please follow other related articles on the PHP Chinese website!