【问题标题】:Vuex - rawModule is undefined moving from single to multiple modulesVuex - rawModule 未定义从单个模块移动到多个模块
【发布时间】:2018-10-16 08:17:55
【问题描述】:

在 documentation 之后将我的项目从 vuex 商店中的单个模块移动到多个。

它声明应该像这样访问特定模块:

store.state.a // -> `moduleA`'s state

这是在访问模块的状态时。它没有说明如何访问 getter 和 mutation 以及特定模块的“commit”和“replaceState”等命令,所以我得出了自己的结论:

store.getters.a
store.mutations.a
store.a.commit()
store.a.replaceState()

1) 这些结论正确吗?

2) 使用这些我会收到一条非常普遍的错误消息:

TypeError: rawModule is undefined

这是我的 store.js:

import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex)
export default new Vuex.Store({
  modules: {
    listingModule: listingModule,
    openListingsOnDashModule: listingsOnDashModule,
    closedListingsOnDashModule: listingsOnDashModule
  }
})

const listingsOnDashModule = {...}
const listingModule = {...}
// their content hasn't changes since the single module approach.

【问题讨论】:

    标签: javascript vue.js vuex


    【解决方案1】:

    这个错误:

    TypeError: rawModule is undefined
    

    是由于尝试将undefined注册为模块引起的,您可能在注册模块时不小心导入了undefined。

    至于store.state.a的语法是正确的。其余的 .a 应该被省略,除非你明确定义了一个命名空间。

    【讨论】:

      猜你喜欢
      • 2018-09-22
      • 2019-12-11
      • 2021-02-01
      • 2010-12-09
      • 2018-10-01
      • 2018-10-27
      • 1970-01-01
      • 1970-01-01
      • 2017-07-25
      相关资源
      最近更新 更多