vue 短信验证码输入

vue 短信验证码输入
在这里插入图片描述

<!DOCTYPE html>
<html lang="zh-cn">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no,viewport-fit=cover">
  <title>cursor-vcode</title>
  <style>
  * {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
  }

  body {
    background-color: #ffffff;
    font-family: -apple-system, PingFang SC, Hiragino Sans GB, Helvetica Neue, Arial;
    -webkit-tap-highlight-color: transparent;
  }

  .app {
    padding-left: 20px;
    padding-right: 20px;
    padding-top: 60px;
    max-width: 320px;
    margin-left: auto;
    margin-right: auto;
  }
  .heading-2 {
    color: #333333;
  }
  .v-code {
    margin-top: 20px;
    display: -webkit-box;
    display: -ms-flexbox;
    display: flex;
    -webkit-box-pack: justify;
    -ms-flex-pack: justify;
    justify-content: space-between;
    -webkit-box-align: center;
    -ms-flex-align: center;
    align-items: center;
    position: relative;
    width: 280px;
    margin-left: auto;
    margin-right: auto;
  }

  .v-code input {
    position: absolute;
    top: -100%;
    left: -666666px;
    opacity: 0;
  }

  .v-code .line {
    position: relative;
    width: 40px;
    height: 32px;
    line-height: 32px;
    text-align: center;
    font-size: 28px;
  }
  .v-code .line::after {
    display: block;
    position: absolute;
    content: '';
    left: 0;
    width: 100%;
    bottom: 0;
    height: 1px;
    background-color: #aaaaaa;
    transform: scaleY(.5);
    transform-origin: 0 100%;
  }
  .v-code .line.animated::before {
    display: block;
    position: absolute;
    left: 50%;
    top: 20%;
    width: 1px;
    height: 60%;
    content: '';
    background-color: #333333;
    animation-name: coruscate;
    animation-duration: 1s;
    animation-iteration-count: infinite;
    animation-fill-mode: both;
  }

  /*.v-code .line.animated::before {
    display: block;
    content: '';
    position: absolute;
    left: 0;
    bottom: -1px;
    width: 100%;
    height: 2px;
    background-color: #000000;
  }*/

  @keyframes coruscate {
    0% {
      opacity: 0
    }
    25% {
      opacity: 0
    }
    50% {
      opacity: 1
    }
    75% {
      opacity: 1
    }
    to {
      opacity: 0
    }
  }
  </style>
</head>

<body>
  <div id="app" class="app">
    <h2 class="heading-2">验证码:</h2>
    <div class="v-code">
      <input
      ref="vcode"
      id="vcode"
      type="tel"
      maxlength="4"
      v-model="aCodes"
      @focus="focused = true"
      @blur="focused = false"
      :disabled="telDisabled">

      <label
        for="vcode"
        class="line"
        v-for="item,index in codeLength"
        :class="{'animated': focused && cursorIndex === index}"
        v-text="codeArr[index]"
      >
      </label>
    </div>
  </div>

  <script src="https://cdn.bootcss.com/vue/2.5.16/vue.min.js"></script>
  <script>
  var app = new Vue({
    el: '#app',
    data: {
      aCodes: '',
      codeLength: 4,
      telDisabled: false,
      focused: false
    },
    computed: {
      codeArr() {
        return this.aCodes.split('')
      },
      cursorIndex() {
        return this.aCodes.length
      }
    },
    watch: {
      aCodes(newVal) {
       // this.aCodes = newVal.replace(/[^\d]/g,'')
        // if (newVal.length > 5) {
        //   // this.telDisabled = true
        //   this.$refs.vcode.blur()
        
        // }
      }
    },
    mounted() {}
  })
  </script>
</body>
</html>
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值