Note: This blog is written word by word by the blogger, which is not easy. Please respect the originality, thank you all!
Problem Description
Send events on the main page to pass parameters to the sub-page throughthis.$bus.$emit
. The sub-page is performing form
form verification and the verification is unsuccessful. TipError in v-on handler: "TypeError: Cannot read properties of undefined (reading 'length')", as shown in the figure below
Solution
First click on the error code line prompted in the console to view the code. It is found that during password verification, the value of value
passed is undefined
undefined. Then this type does not havelength
method, so an error occurred
This error is easy to understand from the literal meaning and printing and debugging by yourself, but here we only know that it is caused by the passedvalue
value type error. You also need to go to the code to check it. Is it a transmission error or an assignment error? So when sending the eventconsole.log
, I output the data to determine whether it was passedpassword
. It turned out that it was not passed
Since no password
parameters were passed when sending the event, then go back to the monitoring page to see if there are password
parameters passed. If so, then A situation like undefined
will occur, and it turns out that I got it herepassword
When
undefined
occurs, most of them are caused by undefined or non-existent parameters, becausepassword
default value is empty String. So the problem is solved after deleting this line of code~