index
import Vue from 'vue'
import Vuex from 'vuex'
import getters from './getters'
import 自定义 from './modules/user' //导入的modules 文件
Vue.use(Vuex)
const store = new Vuex.Store({
modules: {
自定义
},
getters
})
export default store
getters
const getters = {
device: state => state.app.device,
}
export default getters
modules内文件封装写法
const state = {
checkboxData: []
}
const mutations = {
GET_CHECKBOX_DATA: (state, args) => {
state.checkboxData = args
},
CLEAR_CHECKBOX_DATA: (state) => {
state.checkboxData = []
}
}
const actions = {}
export default {
namespaced: true, // 多个modules,相同mutations时候,可识别
state,
mutations,
actions
}