解决 “TypeError: Cannot read properties of undefined (reading ‘xxx‘)“

解决 “TypeError: Cannot read properties of undefined (reading ‘xxx‘)”

insert image description here

可能是没定义到该属性

也有可能是后端返回给你的数据没有这个属性或为null  

此时写*{
    
    {
    
     item.xxx || “” }}*会报错

Solution

1. First judge whether there is a value, and then render
<div v-if="!!item.goods">{
   
   { item.invite.nickname }}</div> 
<div v-else>{
   
   { "" }}</div> //没有返回 或者 null 直接填 “”
2. This attribute is only displayed
<div v-if="item?.goods">{
   
   { item.invite.nickname }}</div>
<div v-else>{
   
   { "" }}</div> //没有返回 或者 null 直接填 “”

//If there is no return or null, directly fill in ""
``

Guess you like

Origin blog.csdn.net/m0_63779088/article/details/128008025
Recommended