gpt4 book ai didi

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

转载 作者:搜寻专家 更新时间:2023-10-30 22:24:45 28 4
gpt4 key购买 nike

我在几个模块中构建了我的 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' 导入 getter

代替

从 './getters' 导入 * 作为 getter

关于javascript - Vuex:getter 应该是函数,但模块 "getters.default"中的 "customer"是 {},我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54351580/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com