模式切换
TypeError: Cannot read properties of undefined (reading 'length')
【问题】在通过数组 monthCourseHours 渲染页面时,加上了 length 做判断,但是却报了错误:
bash
{{ monthCourseHours.length > 0 ? monthCourseHours.after_change : 0}}
bash
[Vue warn]: Error in render: "TypeError: Cannot read properties of undefined (reading 'length')"
【解决】再在length前加一级判断undefined
bash
{{ totalCourseHours !== undefined && monthCourseHours.length > 0 ? monthCourseHours.after_change : 0}}
如果解决不了,就使用下面的方式:
bash
{{ monthCourseHours && monthCourseHours.after_change ? monthCourseHours.after_change : '0' }}