美文网首页Vue学习
vuex里定义热加载

vuex里定义热加载

作者: klmhly | 来源:发表于2018-06-12 10:56 被阅读72次
    // 导入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
    }
    
    

    相关文章

      网友评论

        本文标题:vuex里定义热加载

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