美文网首页
vuex热更替

vuex热更替

作者: Amy_yqh | 来源:发表于2018-07-15 18:24 被阅读0次
    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
    }
    
    

    相关文章

      网友评论

          本文标题:vuex热更替

          本文链接:https://www.haomeiwen.com/subject/ojoppftx.html