Detailed explanation of how to use the Vue license plate input component

Detailed explanation of how to use the Vue license plate input component

A simple license plate input component (vue) for your reference, the specific content is as follows

Effect picture:

vue code:

<template>
    <div class="enTer">
      <div class="plateInput" id="plateInput">
        <div class="item" :class="{active: plateInput.input.type === 'p1'}" @click.stop="clickInput('p1')"><span id="p1">{{plateInput.input.value.p1}}</span></div>
        <div class="item" :class="{active: plateInput.input.type === 'p2'}" @click.stop="clickInput('p2')"><span id="p2">{{plateInput.input.value.p2}}</span></div>
        <div class="item" :class="{active: plateInput.input.type === 'p3'}" @click.stop="clickInput('p3')"><span id="p3">{{plateInput.input.value.p3}}</span></div>
        <div class="item" :class="{active: plateInput.input.type === 'p4'}" @click.stop="clickInput('p4')"><span id="p4">{{plateInput.input.value.p4}}</span></div>
        <div class="item" :class="{active: plateInput.input.type === 'p5'}" @click.stop="clickInput('p5')"><span id="p5">{{plateInput.input.value.p5}}</span></div>
        <div class="item" :class="{active: plateInput.input.type === 'p6'}" @click.stop="clickInput('p6')"><span id="p6">{{plateInput.input.value.p6}}</span></div>
        <div class="item" :class="{active: plateInput.input.type === 'p7'}" @click.stop="clickInput('p7')"><span id="p7">{{plateInput.input.value.p7}}</span></div>
        <div class="item" :class="{active: plateInput.input.type === 'p8',new: !plateInput.input.value.p8}" @click.stop="clickInput('p8')"><span id="p8">{{plateInput.input.value.p8}}</span></div>
      </div>
      <div class="bords" v-if="plateInput.input.dialogVisible">
        <div class="bor">
          <div class="btns">
            <button type="primary" size="small" plain @click="hiddenKeybord">Cancel</button>
            <button type="primary" size="small" plain @click="enterWord">Confirm</button>
          </div>
          <ul class="keyboard province" id="province" v-if="plateInput.input.dialogVisible && plateInput.input.type === 'p1'">
            <li v-for="i in Keyboard.province" @click.stop="clickKeyboard(i)">{{i}}</li>
            <li class="delete" @click.stop="clickDelete"><i class="icon">&#xe602;</i>Delete</li>
          </ul>
          <ul class="keyboard province" id="number" v-if="plateInput.input.dialogVisible && plateInput.input.type !== 'p1'">
            <li v-for="i in Keyboard.number" :class="{num: plateInput.input.type === 'p2' && parseInt(i) >= 0 && parseInt(i) <= 9}" @click.stop="clickKeyboard(i)">{{i}}</li>
            <li class="delete deletes" @click.stop="clickDelete"><i class="icon">&#xe602;</i>Delete</li>
          </ul>
        </div>
      </div>
    </div>
</template>
<style scoped lang="scss">
  .enTer{
    .plateInput{
      padding:0 20rpx;
      display: flex;
      justify-content: space-around;
      .item{
        width: 60rpx;
        height: 75rpx;
        border:1rpx solid #FF5100;
        border-radius: 10rpx;
        display: flex;
        justify-content: center;
        align-items: center;
        font-size: 28rpx;
      }
      .active{
        border-color: #3399ff;
      }
    }
    .bords{
      position: fixed;
      bottom: 0;
      left: 0;
      z-index: 999;
      .bor{
        position: relative;
        .btns{
          width: 100%;
          height: 70rpx;
          background: #fff;
          border-top:1rpx solid rgba(0,0,0,0.05);
          position: absolute;
          display: flex;
          justify-content: space-between;
          align-items: center;
          top: -70rpx;
          left: 0;
          button{
            margin:0;
          }
        }
      }
      //Keyboard.keyboard{
        position:fixed;
        bottom:0;
        left:0;
        background-color:#ced2d9;
        width:100%;
        height:360rpx;
        margin:0;
        padding:0;
        font-size:36rpx;
        z-index:1;
      }
      .keyboard li {
          list-style:none;
          border-radius:10rpx;
      }
      .keyboard li {
          float:left;
          background-color:#fefefe;
          margin-left:15rpx;
          margin-top:15rpx;
      }
      .num{
        color: rgba(0,0,0,0.15);
      }
      .province{
        position: relative;
      }
      .provinces{
        position: relative;
      }
      .province li{
          width:calc((100% - 15rpx * 11) / 10);
          height:calc((100% - 15rpx * 5) / 4);
          display:flex;
          display:-webkit-flex;
          align-items:center;
          -webkit-align-items:center;
          justify-content: center;
          -webkit-justify-content: center;
      }
      .province li.delete{
          width:calc((100% - 15rpx * 11) / 10 * 2 + 15rpx);
      }
      .province li.deletes{
          width:calc((100% - 15rpx * 11) / 10 * 2 + 90rpx);
      }
      .disabled{
        color: rgba(0,0,0,0.15);
      }
    }
  }
</style>

event:

export let life = {
  created () {
    // this.currentPlate = this.plateNumber
    // console.log(this.plateNumber)
    // this.EnterPlateNumber.input.firstWord = this.plateNumber.slice(0,1)
    // this.EnterPlateNumber.input.secondWord = this.plateNumber.slice(1,2)
    // this.EnterPlateNumber.input.lastWords = this.plateNumber.slice(2,9)
  }
}
export let event = {
  clickInput (type) {
    this.methods('clickInput',type)
  },
  clickKeyboard (val) {
    if (this.plateInput.input.type === 'p2' && parseInt(val) >= 0 && parseInt(val) <= 9) return
    this.methods('clickKeyboard', val)
    this.methods('setPlateNumber')
    this.methods('setDirectIssuedPlateNumber')
  },
  //Delete the license plate clickDelete () {
    this.methods('clickDelete')
    this.methods('setPlateNumber')
    this.methods('setDirectIssuedPlateNumber')
  },
  hiddenKeybord(){
    this.methods('hiddenKeybord')
  },
  enterWord(){
    this.methods('enterWord')
  }
}
export let watch = {}

methods:

export default class {
  clickInput(type){
    this.plateInput.input.type = type
    this.plateInput.input.dialogVisible = true
  }
  hiddenKeybord(){
    this.plateInput.input.dialogVisible = false
  }
  enterWord(){
    this.plateInput.input.dialogVisible = false
  }
  clickKeyboard (val) {
    this.plateInput.input.value[this.plateInput.input.type] = val
    let type = this.plateInput.input.type.split('p')[1]
    if (type !== '8') {
      this.plateInput.input.type = 'p' + (parseInt(type) + 1)
    }
  }
  clickDelete () {
    this.plateInput.input.value[this.plateInput.input.type] = undefined
    let nu = this.plateInput.input.type.split('p')[1]-1
    if(nu>=0){
      this.plateInput.input.value['p'+nu] = undefined
    }
    let type = this.plateInput.input.type.split('p')[1]
    if (type !== '1') {
      this.plateInput.input.type = 'p' + (parseInt(type) - 1)
    }
  }
  setPlateNumber () {
    if (this.plateInput.input.plateNumber) {
      this.plateNumber1 = this.plateInput.input.plateNumber
    }else{
      this.plateNumber1 = undefined
    }
  }
  setDirectIssuedPlateNumber () {
    if (this.plateInput.input.plateNumber) {
      this.plateNumber1 = this.plateInput.input.plateNumber
    }else{
      this.plateNumber1 = undefined
    }
  }

}

Model data:

export let props = ['name','plateNumber','noRightPart']
export let model = {
  currentPlate:undefined,
  plateInput:{
    input:{
      value:{
        p1:'Gui',
        p2:'B',
        p3:2,
        p4:2,
        p5:2,
        p6:2,
        p7:2,
        p8:0
      },
      type:'p1',
      dialogVisible:false
    }
  },
  Keyboard: {
    province: ['Beijing', 'Tianjin', 'Hebei', 'Shanxi', 'Inner Mongolia', 'Liaoning', 'Jilin', 'Heilongjiang', 'Shanghai', 'Jiangsu', 'Zhejiang', 'Anhui', 'Fujian', 'Ganzhou', 'Shandong', 'Henan', 'Hubei', 'Xiang', 'Guangdong', 'Qiong', 'Chongqing', 'Sichuan', 'Guizhou', 'Yunnan', 'Tibet', 'Shaanxi', 'Gansu', 'Qinghai', 'Nanjing', 'Xinjiang', 'Taiwan', 'Hong Kong', 'Macao', 'Embassy', 'Consulate', 'Police', 'Education'],
    number: ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C','D', 'E', 'F', 'G','H', 'J', 'K', 'L', 'M', 'N', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '学', '香港', '澳']
  },
}
export let computed = {
  plateNumber1 : {
    get () {
      return this.plateNumber||''
    },
    set (val) {
      this.$emit('update:plateNumber', val)
    }
  }
}

Because a unique framework is used here, the corresponding life cycle functions are placed in the normal Vue project position as needed, the event is written as a normal function, the methods are the methods in the normal methods of i, and the model is the data returned in the data.

For tutorials on vue.js components, please click on the special vue.js component learning tutorial to learn.

For more Vue learning tutorials, please read the special topic "Vue Practical Tutorial"

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:
  • Use Vue3+Vant component to implement App search history function (sample code)
  • Vue elementui implements the example code of the search bar public component encapsulation
  • Detailed explanation of the encapsulation and application of Vue2.x general condition search components
  • Vue component practice searchable drop-down box function
  • Implementation code of Vue drop-down menu component (including search)
  • Vue.js project el-input component listens to the enter key to implement the search function example
  • Implementing a custom component for searchable drop-down box based on Vue
  • Vue component implements searchable drop-down box extension
  • Detailed explanation of the use of Vue2.0 multi-condition search component
  • Detailed explanation of how to use the Vue license plate search component

<<:  MySQL Server 8.0.13.0 Installation Tutorial with Pictures and Text

>>:  Detailed explanation of accessing MySQL database in Linux virtual machine under Windows environment

Recommend

Implementation of mysql backup strategy (full backup + incremental backup)

Table of contents Design scenario Technical Point...

Implementation of k8s node rejoining the master cluster

1. Delete node Execute kubectl delete node node01...

Tomcat uses thread pool to handle remote concurrent requests

By understanding how tomcat handles concurrent re...

MySQL encryption and decryption examples

MySQL encryption and decryption examples Data enc...

Nginx load balancing algorithm and failover analysis

Overview Nginx load balancing provides upstream s...

HTML table markup tutorial (18): table header

<br />The header refers to the first row of ...

A brief discussion on order reconstruction: MySQL sharding

Table of contents 1. Objectives 2. Environmental ...

Details on overriding prototype methods in JavaScript instance objects

Table of contents In JavaScript , we can usually ...

How to start and stop SpringBoot jar program deployment shell script in Linux

Without further ado, let me give you the code. Th...

A complete guide to CSS style attributes css() and width() in jQuery

Table of contents 1. Basic use of css(): 1.1 Get ...

Top 10 Js Image Processing Libraries

Table of contents introduce 1. Pica 2. Lena.js 3....

Detailed explanation of the use of Vue.js draggable text box component

Table of contents Registering Components Adding C...