简体   繁体   English

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

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

I structured my Vuex store in several modules and now I'm facing a strange Vuex error that I am unable to solve: 我在几个模块中构建了我的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)

The Structure of my Vuex store is build on the following pattern 我的Vuex商店的结构基于以下模式

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

Here is my sores basic index.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
  }
})

my modules/customer/index.js: 我的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
}

my modules/customer/getters.js: 我的模块/ customer / getters.js:

const customers = state => state.customers

export default {
  customers
}

I'm not quite sure what is going on here uand why I get this strange error. 我不太清楚这里发生了什么,为什么我会得到这个奇怪的错误。

Any ideas? 有任何想法吗?

This is what worked for me, despite what you did being the example Vuex uses in the documentation. 尽管你所做的是Vuex在文档中使用的示例,但这对我有用。

Use 使用

import getters from './getters'

instead of 代替

import * as getters from './getters'

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

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