admin管理员组文章数量:1414621
I structured my Vuex store in several modules and now I'm facing a strange Vuex error that I am unable to solve:
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
- store
-- index.js
-- modules
--- customer
---- index.js
---- actions.js
---- getters.js
---- mutations.js
Here is my sores basic 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:
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:
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?
I structured my Vuex store in several modules and now I'm facing a strange Vuex error that I am unable to solve:
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
- store
-- index.js
-- modules
--- customer
---- index.js
---- actions.js
---- getters.js
---- mutations.js
Here is my sores basic 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:
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:
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?
Share Improve this question asked Jan 24, 2019 at 16:46 Niko FischerNiko Fischer 2831 gold badge3 silver badges8 bronze badges 01 Answer
Reset to default 4This is what worked for me, despite what you did being the example Vuex uses in the documentation.
Use
import getters from './getters'
instead of
import * as getters from './getters'
本文标签:
版权声明:本文标题:javascript - Vuex: getters should be function but "getters.default" in module "customer" is 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745184944a2646638.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论