美文网首页
vue实现数字验证码,多个输入框

vue实现数字验证码,多个输入框

作者: pomelo_西 | 来源:发表于2019-08-15 10:34 被阅读0次

1. html

<div class="code-wrapper">
    <div class="code-item" v-for="(index, item) in number" :key="index">{{ code[item] }}</div>
    <input class="code-input" v-model="code" :maxlength="number" type="number" pattern="[0-9]*"/>
</div>

2. js

export default {
  data () {
    return {
      code: '',
      number: 6
    }
  }
}

3. css

  .code-wrapper {
    position: relative;
    width: 100%;
    margin-top: .85rem;
    display: flex;
    justify-content: space-between;
    .font-size(36px);
    font-weight: bold;

    .code-item {
      width: 1.07rem;
      height: 1.09rem;
      line-height: 1.09rem;
      border-bottom: .03rem solid @border-color;
      text-align: center;
    }

    .code-input {
      height: 1.09rem;
      position: absolute;
      outline: none;
      color: transparent;
      text-shadow: 0 0 0 transparent;
      width: 200%;
      margin-left: -100%;
      border: none;
      background: none;
      -webkit-appearance: none;
    }
  }
//width:200%; margin-left:-100%;是为了优化手机端光标问题

原文地址:https://blog.csdn.net/lovefive5/article/details/84257062

相关文章

网友评论

      本文标题:vue实现数字验证码,多个输入框

      本文链接:https://www.haomeiwen.com/subject/fcmajctx.html