热更新

import Vuex from 'vuex'

import defaultState from './state/state'
import mutations from './mutations/mutations'
import getters from './getters/getters'
import actions from './actions/actions'

const isDev = process.env.NODE_ENV === 'develpment';
export default () => {
  const store =  new Vuex.Store({
    strict: isDev , // 规范开发,禁止在非mutations内修改data的数据,正式环境改为false
    state: defaultState,
    mutations,
    getters,
    actions,
  })
  if(module.hot){
    module.hot.accept([
      './state/state',
      './mutations/mutations',
      './actions/actions',
      './getters/getters'
    ], ()=> {
      const  newState =require('./state/state').default;
      const  newmutations =require('./mutations/mutations').default;
      const  newActions =require('./actions/actions').default;
      const  newGetters =require('./getters/getters').default;

      // 热更新
      store.hotUpdate({
        state:newState,
        mutations:newmutations,
        getters:newActions,
        actions:newGetters,
      })
    })
  }
  return store
}
posted @ 2021-12-02 14:10  我的世界开始下雪  阅读(28)  评论(0编辑  收藏  举报