美文网首页
Vuex之热更新

Vuex之热更新

作者: 王童孟 | 来源:发表于2018-09-13 09:16 被阅读0次

    vuex 热更新

    // store.js
    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 === 'development'
    export default () => {
      const store = new Vuex.Store({ // 不直接 export
        strict: isDev,
        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: newGetters,
            actions: newActions
          })
        })
      }
    
      return store
    }
    
    

    相关文章

      网友评论

          本文标题:Vuex之热更新

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