vuex热更替

2018-07-15  本文已影响0人  Amy_yqh
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
}

上一篇下一篇

猜你喜欢

热点阅读