vue v-if:"TypeError: Cannot read property 'length' of undefined"
程序员文章站
2022-03-21 20:45:07
在使用v-if判断一个数组大小为0时,会出现 length 是undefined的错误:[Vue warn]: Error in render: "TypeError: Cannot read property 'length' of undefined" 错误代码: 造成这个错误的原因是因为,没有 ......
在使用v-if判断一个数组大小为0时,会出现 length 是undefined的错误:
[vue warn]: error in render: "typeerror: cannot read property 'length' of undefined"
错误代码:
<group v-if="item.detailentitylist.length===0" style="margin-top:-22px;">
<div style="text-align:center;font-size:14px;padding:10px 0;color:#f76260;">
暂无信息
</div>
</group>
造成这个错误的原因是因为,没有预先判断数组是否存在,需要先对数组进行非空验证:item.detailentitylist!=undefined
修正代码:
<group v-if="item.detailentitylist!=undefined && item.detailentitylist.length==0" style="margin-top:-22px;">
<div style="text-align:center;font-size:14px;padding:10px 0;color:#f76260;">
暂无信息
</div>
</group>
上一篇: 最长公共子序列(DP)
推荐阅读
-
js 报错 Uncaught TypeError: Cannot read property 'trim' of undefined
-
Vue报错:Uncaught TypeError: Cannot assign to read only property’exports‘ of object
-
Extjs4---Uncaught TypeError: Cannot read property ‘items’ of undefined
-
Vue报错:Uncaught TypeError: Cannot assign to read only property’exports‘ of object’#
-
el-tooltip组件中content使用Vue-i18n报错TypeError: Cannot read property ‘$t‘ of null
-
vuejs路由使用的问题Error in render function: "TypeError: Cannot read property 'matched' of undefined"
-
Vue报错:Uncaught TypeError: Cannot assign to read only property’exports‘ of object
-
Vue components Cannot read property '__ob__' of undefined
-
Vue引入echarts报错Error in mounted hook: “TypeError: Cannot read property ‘getAttribute‘ of null“
-
vue3 使用axios 会报错“Uncaught TypeError: Cannot read property ‘get‘ of undefined”