账号密码登录
微信安全登录
微信扫描二维码登录

登录后绑定QQ、微信即可实现信息互通

手机验证码登录
找回密码返回
邮箱找回 手机找回
注册账号返回
其他登录方式
分享
  • 收藏
    X
    vuex 为什么需要添加热重载?
    25
    0

    最近看vuex的官网,发现可以对vuex进行热重载。我想问下为什么要对vuex 进行热重载,这有什么用吗,或者对那些业务场景有帮助。谢谢解答?。

    // store.js
    import Vue from 'vue'
    import Vuex from 'vuex'
    import mutations from './mutations'
    import moduleA from './modules/a'
    
    Vue.use(Vuex)
    
    const state = { ... }
    
    const store = new Vuex.Store({
      state,
      mutations,
      modules: {
        a: moduleA
      }
    })
    
    if (module.hot) {
      // 使 action 和 mutation 成为可热重载模块
      module.hot.accept(['./mutations', './modules/a'], () => {
        // 获取更新后的模块
        // 因为 babel 6 的模块编译格式问题,这里需要加上 `.default`
        const newMutations = require('./mutations').default
        const newModuleA = require('./modules/a').default
        // 加载新模块
        store.hotUpdate({
          mutations: newMutations,
          modules: {
            a: newModuleA
          }
        })
      })
    }
    0
    打赏
    收藏
    点击回答
        全部回答
    • 0
    更多回答
    扫一扫访问手机版
    • 回到顶部
    • 回到顶部