当前位置:网站首页>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..
边栏推荐
猜你喜欢
随机推荐
v-on基本使用、参数传递、修饰词
由中序遍历和前序遍历得到后序遍历(树的遍历)
Phospholipid-polyethylene glycol-azide, DSPE-PEG-Azide, DSPE-PEG-N3, MW: 5000
每日五道面试题总结 22/7/19
vue3 访问数据库中的数据
1.13 学习JS
利用 nucleo stm32 f767zi 进行USART+DMA+PWM输入模式 CUBE配置
SQL分类、DQL(数据查询语言)、以及相应SQL查询语句演示
Small program van-cell line wrapping can be left-aligned
暴力方法求解(leetcode14)查找字符串数组中的最大公共前缀
L1-043 阅览室 (20分)
每日五道面试题总结 22/7/26
URL module
C语言中关于2的n次方求值问题(移位运算)
The querystring module
Guangzhou Huawei Interview Summary
Relative and absolute paths
C语言 void和void *(无类型指针)
__dirname
线程池(线程池介绍与使用)









