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

How to modify the default submission method of the form

The default submission method of html is get inste...

vue-router hook function implements routing guard

Table of contents Overview Global hook function R...

A detailed explanation of the subtle differences between Readonly and Disabled

Readonly and Disabled both prevent users from chan...

Using JS to implement binary tree traversal algorithm example code

Table of contents Preface 1. Binary Tree 1.1. Tra...

mysql charset=utf8 do you really understand what it means

1. Let's look at a table creation statement f...

MySQL 8.0.12 winx64 detailed installation tutorial

This article shares the installation tutorial of ...

Perfect solution to MySQL common insufficient memory startup failure

1. If MySQL is not started successfully, check th...

HTML+CSS to achieve charging water drop fusion special effects code

Table of contents Preface: accomplish: Summarize:...

CSS to implement sprites and font icons

Sprites: In the past, each image resource was an ...

How to optimize a website to increase access speed update

Recently, the company has begun to evaluate all s...

Complete step record of vue encapsulation TabBar component

Table of contents Implementation ideas: Step 1: C...

Vue's global watermark implementation example

Table of contents 1. Create a watermark Js file 2...

Detailed steps for yum configuration of nginx reverse proxy

Part.0 Background The company's intranet serv...

Steps to use ORM to add data in MySQL

【Foreword】 If you want to use ORM to operate data...