什么是Vuex?
vuex是一个专门为vue.js设计的集中式状态管理架构。状态?我把它理解为在data中的属性需要共享给其他vue组件使用的部分,就叫做状态。简单的说就是data中需要共用的属性。
1.在vue 组件中
执行enabledcheckbox方法 ,true 为参数,用来改变state中的值
 this.$store.dispatch("enabledcheckbox",true) 
从state获取useredit的值
this.$store.state.useredit
2 在vuex导出的对象对添加 值到state
添加 mutations 来改变state的值
添加 actions 来 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)
在main.js
import store from './vuex'
new Vue({
 el: '#app',
 router,
 store,
 render:h=>h(App)
})
总结
以上所述是小编给大家介绍的vuex 的简单使用,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对脚本之家网站的支持!