当前位置:网站首页>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..
边栏推荐
猜你喜欢
随机推荐
C语言 内联函数
第一篇博客
6.24今日学习
STM32 触发HardFault_Handler如何查找原因
利用 nucleo stm32 f767zi 进行USART+DMA+PWM输入模式 CUBE配置
L1-039 古风排版(C)
每日五道面试题总结 22/7/23
枚举法方法:(leetcode1300)转变数组后最接近目标值的数组和
Living to detect the Adaptive Normalized Representation Learning for GeneralizableFace Anti - Spoofing reading notes
一分种一起来了解Vite的基础
1.11今日学习
每日五道面试题总结 22/7/19
环形链表---------约瑟夫问题
猴子选大王(约瑟环问题)
三月底啦啦
ES6介绍+定义变量+不同情况下箭头函数的this指向
require模块化语法
广州华为面试总结
Source Insight 使用教程(2)——常用功能
啃瓜记录第一天