您的位置:首页 > 产品设计 > UI/UE

vuex 简单使用

2018-03-22 10:57 239 查看
在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)
})
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  vue vuex