渲染函数中的错误:“TypeError:无法读取未定义的属性",使用 Vuex 和 Vue Router [英] Error in render function: “TypeError: Cannot read property of undefined”, using Vuex and Vue Router

查看:50
本文介绍了渲染函数中的错误:“TypeError:无法读取未定义的属性",使用 Vuex 和 Vue Router的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在使用 Vue、Vuex 和 Vue-Router 处理一个问题.我正在构建一个闪存卡应用程序,在创建主应用程序时获取所有卡片,然后使用 Vuex getter 通过其作为路由参数传递的 id 获取每张卡片.

相关位:

App.vue

出口默认{成分: {'app-header':标题,},数据() {返回 {}},创建(){this.$store.dispatch('getAllCards');}}

dispatch('getAllCards') 只是从数据库中提取所有卡片并提交到 Vuex store.js.

现在我设置了一个getter:

getter: {cardById: (状态) =>(id) =>{return state.allCards.find((card) => card._id === id);}}

这是Card.vue: