编程语言
首页 > 编程语言> > javascript-Vuex:getters应该是函数,但是模块“ customer”中的“ getters.default”是{}

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

作者:互联网

我在几个模块中构造了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
  }
})

我的模块/客户/ 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
}

我的模块/客户/getters.js:

const customers = state => state.customers

export default {
  customers
}

我不太确定这是怎么回事,为什么我会收到这个奇怪的错误.

有任何想法吗?

解决方法:

尽管您是Vuex在文档中使用的示例,但是这对我还是有用的.

采用

从“ ./getters”导入吸气剂

代替

从“ ./getters”导入*作为getter

标签:vuex,vue-js,javascript
来源: https://codeday.me/bug/20191211/2106717.html