vuex中的getters为什么无法调用啊?

图片描述
console.log(this.$store.getters.getCheckedFiles());

getters: {

getCheckedFiles: state => {
  return state.files.filter(checked => checked.checked);
  // return ids;
}

}

代码如图,无论是在vue组件中调用还是main.js的mutations里面调用均提示

Uncaught TypeError: Cannot read property 'getCheckedFiles' of undefined
Uncaught TypeError: this.$store.getters.getCheckedFiles is not a function

阅读 9.7k
2 个回答

我刚刚仔细阅读文档明白了,getters在别得地方调用不需要括号

也就是vuex将getters里面的函数对外暴露为一个属性,而不是一个方法。

新手上路,请多包涵

写法不对哟,应该是
this.$store.commit('getCheckedFiles');
这样就可以啦

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题