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

https://img1.mukewang.com/5b94e8db0001fa2f07680087.jpg

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


富国沪深
浏览 6367回答 3
3回答

慕盖茨4494581

getters在别得地方调用不需要括号也就是vuex将getters里面的函数对外暴露为一个属性,而不是一个方法。

Alice_hhu

getters 是属性,不是方法,直接访问,而不是用方法的调用方式console.log(this.$store.getters.getCheckedFiles);

繁华开满天机

写法不对哟,应该是this.$store.commit('getCheckedFiles');这样就可以啦
打开App,查看更多内容
随时随地看视频慕课网APP