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:methods
login
validate
promise
At this time, according to the previous verification rules, there is a problem. So return false
. Let's take a correct example: