当前位置:网站首页>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..
边栏推荐
猜你喜欢
随机推荐
Small program van-cell line wrapping can be left-aligned
uniapp | 官方提供的map组件使用问题
docker中配置mysql 5.7
针对简历上的问题
uniapp | 开发中遇到的兼容性问题(待续)
区间问题 : 今年暑假不AC
v-bind用法:类动态绑定对象 数组 style样式 及函数方法
SQL:DDL、DML、DQL、DCL相应介绍以及演示
ES6数组的扩展方法map、filter、reduce、fill和数组遍历for…in for…of arr.forEach
一分种一起来了解Vite的基础
猴子选大王(约瑟环问题)
每日五道面试题总结 22/7/21
canvas--饼状图
URL模块
啃瓜记录又一天
meime模块
宝塔邮局邮箱设置成功后能发送不能接收问题处理
面试总结 22/7/22 面试中的重点
每日五道面试题总结 22/7/20
L1-039 古风排版(C)