Vue implements verification whether the username is available

Vue implements verification 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

Verify that the username is available

Case Effect

Implementation steps (ideas)

1. Data binding through v-model
2. Prompt information is required
3. A listener is needed to monitor changes in input information
4. Events that need to be modified

Further adjustments are

1. Use a listener to monitor changes in user names
2. If the user name changes (call the backend interface for verification)
3. Adjust the prompt information according to the verification results

Code

Basic layout

<div id="app">
  <span>Username:</span>
  <span>
   <input type="text" v-model.lazy="uname">
  </span>
  <span>
   {{tip}}
  </span>
</div>

Implement specific functions through listeners

<script type="text/javascript" src="../js/vue.js"></script>
 <script type="text/javascript">
  /* Listener uses the listener to monitor changes in the user name. If the user name changes (call the background interface for verification)
  Adjust the prompt information according to the verification results*/
  var vm = new Vue({
   el: "#app",
   data: {
    uname: '',
    tip: ''
   },
   methods: {
    checkName: function (uname) {
     //Call the interface, but you can use the scheduled task to simulate the interface call var that = this;
     setTimeout(function () {
      // Simulate interface call if (uname == 'admin') {
       that.tip = 'The user name already exists, please change it'
      } else {
       that.tip = 'Username can be used'
      }
     }, 1000)
    }
   },
   watch:
    uname: function (val) {
     //Call the backend interface to verify the legitimacy of the user name this.checkName(val);
     this.tip = 'Verifying...'
    }
   },

  });
</script>

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:
  • 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
  • Vue method to verify whether the username is available

<<:  Steps to install MySQL 5.7.10 on Windows server 2008 r2

>>:  Detailed explanation of crontab scheduled execution command under Linux

Recommend

Detailed explanation of using MySQL where

Table of contents 1. Introduction 2. Main text 2....

Dockerfile implementation code when starting two processes in a docker container

I want to make a docker for cron scheduled tasks ...

An article to deal with Mysql date and time functions

Table of contents Preface 1. Get the current time...

Summary of MySQL usage specifications

1. InnoDB storage engine must be used It has bett...

Detailed steps for smooth transition from MySQL to MariaDB

1. Introduction to MariaDB and MySQL 1. Introduct...

Method of realizing automated deployment based on Docker+Jenkins

Use Code Cloud to build a Git code storage wareho...

Installation of mysql-community-server. 5.7.18-1.el6 under centos 6.5

Use the following command to check whether MySQL ...

Detailed steps to install Docker 1.8 on CentOS 7

Docker supports running on the following CentOS v...

How to delete table data in MySQL

There are two ways to delete data in MySQL, one i...

Difference between varchar and char types in MySQL

Table of contents aforementioned VARCHAR Type VAR...

Make your website automatically use IE7 compatibility mode when browsing IE8

Preface To help ensure that your web pages have a ...