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
我刚刚仔细阅读文档明白了,getters在别得地方调用不需要括号
也就是vuex将getters里面的函数对外暴露为一个属性,而不是一个方法。