Front-end learning (2686): Reread the login pre-check of vue e-commerce website 7

 

When we click the login button, we should not directly initiate a network request, but should pre-check the form, and send the request only after the verification is successful.


Once you get the form reference object, you can verify the form.

First, pass the login button  @click to bind an event. Next,   add a   method to it. The function parameter is a callback function. The callback function will be called after the verification is completed, and pass in two parameters: whether the verification is successful and the fields that have not passed the verification. If you don't pass in the callback function, it will return one.  At this point, we click the login button to see if the pre-check has been performed:

methodsloginvalidatepromise


At this time, according to the previous verification rules, there is a problem. So return  false. Let's take a correct example:

 

Guess you like

Origin blog.csdn.net/weixin_43392489/article/details/110773536