Vue: error in render: “typeerror: cannot read property ‘length’ of undefined”
There are usually two situations:
1. Using length to report an error on the HTML tag of the template
When length is used in Vue, an error is sometimes reported as follows:
<div class="item_list" v-if="form.checkVal.length > 0" >list 1</div>
<div class="item_list" v-else >list 2</div>
resolvent:
Change to: form.checkVal !== undefined && form.checkVal.length > 0
<div class="item_list" v-if="form.checkVal !== undefind && form.checkVal.length > 0" >list 1</div>
<div class="item_list" v-else >list 2</div>
2. Use length in JS to report an error, as follows
if(res.Data.length == 1){
this.tableData1 = res.Data[0];
}
Error reason: at this time res.Data No data is undefined, so it cannot be found res.Data.length .
Solution: in addition to a layer of judgment, the first guarantee res.Data The existence is not null or undefined is changed to, as follows
if(res.Data){
if(res.Data.length == 1){
this.tableData1 = res.Data[0];
}
}
Read More:
- [Solved] vue.runtime.esm.js?2b0e:619 [Vue warn]: Error in render: “TypeError: Cannot read property ‘length‘
- [Solved] VUE Use Filters Error: [Vue warn]: Error in render: “TypeError: Cannot read property ‘toFixed’ of undefined”
- [Vue warn]: Error in render: TypeError: Cannot read property ‘xxxx’of undefined
- [Solved] Vue + uniapp Uncaught TypeError: Cannot read property ‘getters‘ of undefined
- [Solved] Vue Error: Uncaught TypeError: Cannot read property ‘getters‘ of undefined
- Vue Error in callback for immediate watcher “height”: “TypeError: Cannot read property ‘style’ of
- [Solved] Parcel Package Error: Cannot read property ‘length‘ of undefined
- [Solved] TypeError: Cannot read property ‘indexOf‘ of undefined at VueComponent.resetFields
- Vue ElementUI el-dropdown Error: Uncaught TypeError: Cannot read property ‘disabled‘ of null
- Wechat program typeerror: a solution to cannot read property ‘SetData’ of undefined
- VUE Echarts Loading Error TypeError: Cannot read property getAttribute of null?
- [Solved] Cannot read properties of undefined (reading ‘ajax‘); Cannot read property ‘ajax‘ of undefined
- Uniapp: TypeError: Cannot read property ‘apply‘ of undefined (H5 does not report an error, but the real machine runs with an error)
- VUE: Property or method “deleteFun“ is not defined on the instance but referenced during render. [How to Fix]
- Can’t read property ‘push’ of undefined [How to Solve]
- [Solved] Echarts Error: Cannot read property ‘init‘ of undefined
- cesium CLAMP_TO_GROUND Error Cannot read property ‘globe‘ of undefined
- TypeError: res.render is not a function
- [Solved] Vue Error: Failed to mount component: template or render function not defined