当前位置:网站首页>The Error in the render: "TypeError: always read the properties of null '0' (reading)" Error solution
The Error in the render: "TypeError: always read the properties of null '0' (reading)" Error solution
2022-08-02 03:52:00 【Xiaoru wants to sleep】
I encountered a very interesting problem when I was writing a project recently. When I was about to get a sub-array in an array to the page, I was prompted with an error Error in render: “TypeError: Cannot read properties of null (reading '0')", it can't be read when rendering, what's going on, hurry up to search and find the problem
This is my original error code
<view class="apply-name"><text>{{ item.applicant }}</text><text>{{ item.inspector[0] }}</text></view>Error message
Reason for error
When we call the inspector interface, it is an asynchronous call, and in the rendering mechanism of vue, asynchronous data first displays the initial data (that is, the data that already exists), and then displays the data with data, so when vue starts to execute, there is no data in the inspector, so an error will be reported.
Workaround
The solution is also very simple, that is to add a judgment statement when loading the fragment, v-if="item.inspector" If it is empty, the rendering of the module will not be performed. The modified code is as follows
<view class="apply-name"><text>{{ item.applicant }}</text><text v-if="item.inspector">{{ item.inspector[0] }}</text></view>The solution is solved, but why is v-if so powerful? Are you curious? Let's look down.
Vue performs the following transformation template -> ast -> render function, and finally generates the corresponding DOM according to the generated render function, which will not be expanded here.When generating ast and render functions, Vue parses instructions such as v-if.So when render()
is rendering, v-if has already started to judge, so what I understand is that the data in the inspector has been rendered at this time, so it will not report an error when looking for the data in it again..
边栏推荐
猜你喜欢
随机推荐
uniapp | 使用npm update更新后编译报错问题
配置mmdet来训练Swin-Transformer之一配置环境
npm和package.json
每日五道面试题总结 22/7/20
IO流、字节流、字节缓冲流
COCO数据集训练TPH-YoloV5
6.24今日学习
面试总结 22/7/25 面试中的重点
STM32 CAN过滤器
4.14到新公司的一天
TypeScript 错误 error TS2469、error TS2731 解决办法
uniapp | 开发中遇到的兼容性问题(待续)
---静态页面---
__dirname
PHP图片压缩到指定的大小
针对简历上的问题
轮播图详解(完整代码在最后)
The querystring module
微信小程序九宫格抽奖和转盘抽奖的实现
FreeRTOS内核详解(1) —— 临界段保护原理









