In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces the JavaScript virtual value caused by circular error report how to solve the relevant knowledge, the content is detailed and easy to understand, the operation is simple and fast, has a certain reference value, I believe that after reading this JavaScript false value caused circular error report how to solve the article will have a harvest, let's take a look.
I came across a scene at work today:
When the parent component passes data to the child component, when the data passed by the parent component is cycled in the child component
Sub-component error report
TypeError: Cannot read property 'menu_pid' of null at VueComponent.getTree
Later, it was found that the reason for reporting the error was during the cycle.
GetTree (list, parentId) {
Let re = new Array ()
For (let I = 0; I < list.length; iTunes +) {
Let pid = list [I] .menu _ pid; prompt to report an error here
/ / do something
}
Return re
}
It is found that there is a virtual value [{}, {}, null] in the data passed by the parent component list.
It is this imaginary value null that leads to the wrong report.
Then the code is blocked; the later code cannot be run
How to avoid such problems in the future
When the parent component passes data to the child component
Do not pass virtual values, because virtual values can lead to unexpected errors
When passing the value down; check the value
When looping at the bottom, pay attention to the robustness of the code
Remove imaginary value
Let arr = [11, 22, 33, null,', undefined]
Let newArr = []
For (let I = 0; I < arr.length; iTunes +) {
If (arr [I]) {
NewArr.push (arr [I])
}
}
Console.log (newArr); / / [11, 22, 33]
This is the end of the article on "how to solve cyclic errors caused by JavaScript imaginary values". Thank you for reading! I believe that everyone has a certain understanding of the knowledge of "how to solve the circular error caused by the false value of JavaScript". If you want to learn more knowledge, you are welcome to follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.