Vue报错:Error in v-on handler: “TypeError: Cannot read properties of undefined (reading ‘length‘)“

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

Insert image description here

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 havelengthmethod, so an error occurred

Insert image description here

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

Insert image description here

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

Insert image description here

When undefined occurs, most of them are caused by undefined or non-existent parameters, because password default value is empty String. So the problem is solved after deleting this line of code~

Guess you like

Origin blog.csdn.net/qq_41782425/article/details/132188833
Recommended