Vue implements multi-grid input box on mobile terminal

Vue implements multi-grid input box on mobile terminal

Recently, the company has put forward a requirement to complete the h5 page operation as shown in the figure below.

There weren't many wheels available online, so I made one myself. Without further ado, let's get straight to the code.

<div class="verify-tel">
    <h1>SMS Verification</h1>
    <h2>SMS Verification</h2>
    <div>
        <input ref="pwd" :maxlength="digits.length" v-model="msg" style="position: absolute;z-index: -1;opacity: 0"/>
        <ul class="pwd-wrap" @click="focus">
            <li v-for="(item,key) in digits" :style="{'margin-right': (100-10*digits.length)/(digits.length-1)+'%','width':'10%'}" >
                <span v-if="msgLength > key">{{msg.substring(key,key+1)}}</span>
            </li>
        </ul>
    </div> 
</div>

CSS part (the style content is too complicated, please skip the modification)

html,body{
    width: 100%;
    height: 100%;
    background: #fbf9fe;
  }
  .verify-tel{
    background-color: #f9f9f9;   
    margin: 0 30px;
    >p{
      color: red;
      font-weight: bold;
      margin-top: 40px;
      margin-bottom: 30px;
    }
    >h1{
      font-weight: 400;
      margin-bottom: 0;
    }
    >h2{
      margin-top: 0;
      font-weight: 400;
      font-size: 14px;
      color: #858585;
    }
    .input-box{
      margin-top: 30px;
      >input{
        width: 10%;
        border: none;
        border-bottom: 1px solid grey;
        background-color: #f9f9f9;
        text-align: center;
        margin-right: 18%;
        font-size: 35px;
        &:focus{
          border-bottom: 1px solid deepskyblue;
        }
        &:last-of-type{
          margin-right: 0 !important;
        }
      }
    }
    .btn-box{
      >button{
        height: 40px;
        border: 1px solid #4e8cee;
        color: #4e8cee;
        background-color: white;
        border-radius: 4px;
        width: 30%;
        &:last-of-type{
          float: right;
          width: 65%;
          height: 40px;
          color: white;
          background-color: rgb(78,140,238);
          border-radius: 4px;
        }
      }
    }
  }
  .pwd-wrap{
    padding-left: 0;
    width: 100%;
    height: 44px;
    padding-bottom: 1px;
    margin: 0 auto;
    display: flex;
    display: -webkit-box;
    display: -webkit-flex;
    cursor: pointer;
    border: none;
    background-color: #f9f9f9;
  }
  .pwd-wrap li{
    list-style-type:none;
    text-align: center;
    line-height: 44px;
    -webkit-box-flex: 1;
    flex: 1;
    -webkit-flex: 1;
    border: none;
    border-bottom:1px solid black;
    background-color: #f9f9f9;
    &:last-of-type{
      margin-right: 0 !important;
    }
    >span{
      font-size: 20px;
    }
  }
  .pwd-wrap li:last-child{
    border-right: 0;
  }
  .pwd-wrap li i{
    height: 10px;
    width: 10px;
    border-radius:50% ;
    background: #000;
    display: inline-block;
  }

js part of the code

<script>
  export default{
    data(){
      return {
        page:0, //1 is for SMS verification digits:['','','','','',''], //Input box digit control, how many "input boxes" can be configured here
        msg:'',
        msgLength:0,
      }
    },
    methods:{
      //Mobile phone number verification interface function verifyTels:async function () {
        try{
        }catch(e){
          console.log(e)
        }
      },
      //Make the input box focus focus(){
        this.$refs.pwd.focus(); 
      },
    },
    beforeMount:function () {
        //Because my business needs require multiple pages, and digits are transmitted from the parent component, I hide it and only one line of code remains.
        this.page=1;
    },
    watch:
      msg(curVal){
        //Monitor the input length. If the input is complete, automatically call the verification interface function if(curVal.trim().length===this.digits.length){
           this.verifyTels(); 
        }
        this.msgLength = curVal.length;
      },
      'page':{
        handler:function (newValue, oldValue) {
          if(oldValue==0&&newValue==1){
            //When entering the page for the first time, the focus is automatically obtained. This can be optimized.
            this.timer = setTimeout(()=>{this.$refs.pwd.focus()},500);
          }
        },
        deep:true
      }
    },
    beforeDestroy:function () {
      clearTimeout(this.timer);
    }
  }
</script>

If you have any questions, please contact me to make corrections. Convenient for everyone to use

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:
  • Problems with implementing IP input box on mobile side of Vue project
  • Vue2.0 implements the real-time retrieval and update list function of the mobile input box

<<:  HTML table tag tutorial (36): table header background color attribute BGCOLOR

>>:  PHP related paths and modification methods in Ubuntu environment

Recommend

Linux common commands chmod to modify file permissions 777 and 754

The following command is often used: chmod 777 文件...

Ubuntu 20.04 connects to wifi (2 methods)

I recently installed Ubuntu 20.04 and found that ...

JavaScript implements the generation of 4-digit random verification code

This article example shares the specific code for...

React nested component construction order

Table of contents In the React official website, ...

A brief analysis of mysql index

A database index is a data structure whose purpos...

How to use xshell to connect to Linux in VMware (2 methods)

【Foreword】 Recently I want to stress test ITOO...

MySQL changes the default engine and character set details

Table of contents 1. Database Engine 1.1 View dat...

CentOS 6.4 MySQL 5.7.18 installation and configuration method graphic tutorial

The specific steps of installing mysql5.7.18 unde...

Detailed tutorial on deploying Springboot or Nginx using Kubernetes

1 Introduction After "Maven deploys Springbo...

MySQL series: Basic concepts of MySQL relational database

Table of contents 1. Basic Concepts 2. Developmen...

Web design skills: iframe adaptive height problem

Maybe some people have not come across this issue ...

MySQL Innodb key features insert buffer

Table of contents What is insert buffer? What are...

How to modify port 3389 of Windows server 2008 R2 remote desktop

The default port number of the Windows server rem...

VMware 15.5 version installation Windows_Server_2008_R2 system tutorial diagram

1. Create a new virtual machine from VMware 15.5 ...