简体   繁体   中英

[Vue warn]: Error in render: "TypeError: Cannot read property 'type' of undefined"

My array has a data. Why did this error pop up in my console:

Error in render: "TypeError: Cannot read property 'type' of undefined"

vue code inside method:

getRoomType(assign_id){
 return this.roomTypeName.find(o => o.room_id === parseInt(assign_id)).type;
},

vue html:

<span>{{ option.value }} ({{(option.assign_id=='no')? 'unassign' : getRoomType(option.assign_id) }})</span>

error: 错误信息

I finally solved my problem.

Solution:( check the length of the array before returning value, to ensure that there is data to be returned. )

getRoomType(assign_id){
    return (this.roomTypeName.length > 0)? this.roomTypeName.find(element => element.room_id === parseInt(assign_id)).type :'error';
},

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM