vue.js - vuex中的getters为什么无法调用啊?

查看:1364
本文介绍了vue.js - 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

解决方案

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

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

这篇关于vue.js - vuex中的getters为什么无法调用啊?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆