繁体   English   中英

Vuex:getter应该是函数,但模块“customer”中的“getters.default”是{}

[英]Vuex: getters should be function but “getters.default” in module “customer” is {}

我在几个模块中构建了我的Vuex存储,现在我遇到了一个我无法解决的奇怪的Vuex错误:

Uncaught Error: [vuex] getters should be function but "getters.default" in module "customer" is {}.
at assert (vuex.esm.js?358c:97)
at eval (vuex.esm.js?358c:271)
at eval (vuex.esm.js?358c:85)
at Array.forEach (<anonymous>)
at forEachValue (vuex.esm.js?358c:85)
at eval (vuex.esm.js?358c:270)
at Array.forEach (<anonymous>)
at assertRawModule (vuex.esm.js?358c:265)
at ModuleCollection.register (vuex.esm.js?358c:191)
at eval (vuex.esm.js?358c:205)

我的Vuex商店的结构基于以下模式

- store
-- index.js
-- modules
--- customer
---- index.js
---- actions.js
---- getters.js
---- mutations.js

这是我的疮基本index.js:

import Vue from 'vue'
import Vuex from 'vuex'
import customerModule from './modules/customer/index'
import globalModule from './modules/global/index'
import projectModule from './modules/project/index'

Vue.use(Vuex)

export default new Vuex.Store({
  modules: {
    customer: customerModule,
    global: globalModule,
    project: projectModule
  }
})

我的modules / customer / index.js:

import * as actions from './actions'
import * as getters from './getters'
import * as mutations from './mutations'

const state = {
  customers: []
}

export default {
  namespaced: true,
  state: state,
  actions: actions,
  mutations: mutations,
  getters: getters
}

我的模块/ customer / getters.js:

const customers = state => state.customers

export default {
  customers
}

我不太清楚这里发生了什么,为什么我会得到这个奇怪的错误。

有任何想法吗?

尽管你所做的是Vuex在文档中使用的示例,但这对我有用。

使用

import getters from './getters'

代替

import * as getters from './getters'

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM