Error in render: "TypeError: Cannot read property ‘avatar_url’ of undefined or Error in render: "TypeError: Cannot read property xxx of undefined
这是最近项目上遇到的问题, 主要在遍历数据的时候, 出现的
原因: 此时的写在template 中的数据为空而且是多层嵌套 如: article.author.avatar_url, reply.author.avatar_url 这时就会出现这种问题, 单层的目前是不会的,这可能和vue的底层有关吧,
解决方法:
这个实际是没有什么问题的,但是看到报错,那一片的红色,还是忍不住要消除它
data() {
return {
article
: {
author
:{},
replies
:[]
},
}
},
在data中添加对应的属性
这样的问题,大致同理这样解决