简体   繁体   English

未捕获的错误:[vuex] getters应该起作用,但是“ getters.default”是{}

[英]Uncaught Error: [vuex] getters should be function but “getters.default” is {}

I recently build my VUE project for production using NPM, however in the console i get the following error. 我最近使用NPM构建了用于生产的VUE项目,但是在控制台中出现以下错误。 Does anyone have any idea why vuex is complaining ? 有谁知道vuex为什么抱怨? npm 3.10 , node.js 8.11, npm 3.10,node.js 8.11,

Uncaught Error: [vuex] getters should be function but "getters.default" is {}.
at assert (vuex.esm.js:97)
at vuex.esm.js:271
at vuex.esm.js:85
at Array.forEach (<anonymous>)
at forEachValue (vuex.esm.js:85)
at vuex.esm.js:270
at Array.forEach (<anonymous>)
at assertRawModule (vuex.esm.js:265)
at ModuleCollection.register (vuex.esm.js:191)
at new ModuleCollection (vuex.esm.js:165)

thank you Tonathiu 谢谢你Tonathiu

I assume you have a function(getter) inside getters of vuex and you are trying to call it using something like 我假设您在vuex的getter中有一个function(getter),并且您正在尝试使用类似

store.getters.default()

Which is a wrong way to do so, and you will get some errors log like that. 这样做是错误的方法,并且您将获得一些错误日志。

So the correct way is to use vuex's mapGetters inside the computed property of the vue component. 因此正确的方法是在vue组件的计算属性内使用vuex的mapGetters。 which would look something like this in the code. 在代码中看起来像这样。

import { mapGetters } from 'vuex'
...
...
  computed:{
            ...mapGetters(['default'])
        },
...
...

And then try calling default getter using this(vm instance) like 然后尝试使用this(vm instance)调用默认getter

this.default()

That's all it should work now. 这就是它现在应该工作的全部。

I hope it helps. 希望对您有所帮助。

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

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