// 导入vuex模块
import Vuex from 'vuex'
// 导入自己写的store的状态文件
import defaultState from './state/state.js'
import mutations from './mutations/mutations.js'
import getters from './getters/getters.js'
import actions from './actions/actions.js'
const isDev = process.env.NODE_ENV === 'development'
//创建store变量
export default () => {
const store = new Vuex.Store({
strict: isDev,
state: defaultState,
mutations: mutations,
getters,
actions
})
//此处开始定义热更新
if (module.hot) {
module.hot.accept([
'./state/state.js',
'./mutations/mutations.js',
'./getters/getters.js',
'./actions/actions.js'
], () => {
const newState = require('./state/state.js').default
const newMutations = require('./mutations/mutations.js').default
const newGetters = require('./getters/getters.js').default
const newActions = require('./actions/actions.js').default
store.hotUpdate({
state: newState,
mutations: newMutations,
getters: newGetters,
actions: newActions
})
})
}
return store
}
网友评论