Vue method to verify whether the username is available

Vue method to verify whether the username is available

This article example shares the specific code of Vue to verify whether the username is available for your reference. The specific content is as follows

When entering a name in the input box, verify whether it exists when losing focus. If it already exists, prompt to re-enter it. If it does not exist, prompt that it can be used.

The code is as follows

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Listener Example</title>
    <script src="../js/vue.js" type="text/javascript" charset="UTF-8"></script>
</head>
<body>
    <div id="app">
        <input type="text" v-model.lazy="msg"> <span> {{ span1 }}</span>
    </div>
    <script>
        // The listener listens to the current data changes. When the data in the text box loses focus,
        // Take the value in the text box to the backend for operation, make a judgment based on the data returned by the backend, and give a prompt var vm = new Vue({
            el: "#app",
            data: {
                msg: "",
                span1: "",
            },
            methods: {
                show1: function (val) {//The val here is the value in the text box//Execute asynchronous request, go to the background to get data, simulate going to the background to get data var that = this; //Because there is also a this object in setTimeout, this object is the document object setTimeout(function () { //If val is written here, it will not enter the if if (val === "aaa") {
                            that.span1 = "The user name is not available, please change it";
                        } else {
                            that.span1 = "Username can be used";
                        }
                    }, 2000);
                }
            },
            watch:
                msg: function (val) {
                    this.show1(val);
                    this.span1 = "Verifying";
                },
            }
        })
    </script>
</body>
</html>

The effect is as follows

The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM.

You may also be interested in:
  • Vue implements verification whether the username is available
  • Go+Vue development process of an online food delivery application (username password and graphic verification code)
  • Vue+element-ui integrates random verification code + username + password form verification function

<<:  mysql trigger creation and usage examples

>>:  Vue simulates the shopping cart settlement function

Recommend

Use Navicate to connect to MySQL on Alibaba Cloud Server

1. First enter the server's mysql to modify p...

CSS achieves highly adaptive full screen

When writing my own demo, I want to use display:f...

In-depth analysis of MySQL query interception

Table of contents 1. Query Optimization 1. MySQL ...

HTML n ways to achieve alternate color code sample code

This article mainly introduces the sample code of...

Detailed explanation of common Docker commands

1. Help Command 1. View the current Docker versio...

Seven Principles of a Skilled Designer (2): Color Usage

<br />Previous article: Seven Principles of ...

An article to give you a deep understanding of Mysql triggers

Table of contents 1. When inserting or modifying ...

Discuss the development trend of Baidu Encyclopedia UI

<br />The official version of Baidu Encyclop...

Master-slave synchronization configuration of Mysql database

Table of contents Mysql master-slave synchronizat...

Chrome monitors cookie changes and assigns values

The following code introduces Chrome's monito...

A brief description of the relationship between k8s and Docker

Recently, the project uses kubernetes (hereinafte...

Detailed explanation of the use of MySQL select cache mechanism

MySQL Query Cache is on by default. To some exten...

Implementation of waterfall layout + dynamic rendering

Table of contents Typical waterfall website Water...