1.0.5 • Published 4 years ago

vue-verification-input v1.0.5

Weekly downloads
2
License
MIT
Repository
github
Last release
4 years ago

vue-verification-input

方形验证码框 支持快速粘贴

链接

demo npm

用法

$ yarn add vue-verification-input -S
# or
$ npm i vue-verification-input -S
  1. 全局组件使用

    import Vue from 'vue'
    import VerificationCodeInput from 'vue-verification-input'
    Vue.component('VerificationCodeInput', VerificationCodeInput)
  2. 局部组件

    import VerificationCodeInput from 'vue-verification-input'
    export default {
      components: {
        VerificationCodeInput
      }
    }
  3. template

    <verification-code-input
        :wrong="[Boolean]"
        :type="[String]"
        :item-class="[String]"
        :max-length="[Number]"
        item-margin="20px 10px"
        :item-active-class="[String]"
        :item-wrong-class="[String]"
        @deleteEvent="deleteEvent"
        @finishEvent="finishEvent"
    ></verification-code-input>
    Props描述默认值必须/可选
    wrong用来控制验证框的状态false必须
    typeInput 类型,一般选用 tel或texttel可选
    item-class单个框的样式如下可选
    max-length输入框个数6可选
    item-margin单个框左右和上下的间距10px 0可选
    item-active-class单个框输入时的高亮样式如下可选
    item-wrong-class错误回调后的每个框的高亮样式如下可选
    // item-class item-active-class item-wrong-class 的默认样式
    .item-class {
      height: 50px;
      width: 40px;
      border: 1px solid #f8f8f8;
      background: #f8f8f8;
      border-radius: 5px;
      font-size: 22px;
      color: #333333;
    }
    
    .item-active-class {
      border: 1px solid #14B9C8;
    }
    
    .item-wrong-class {
      border: 1px solid #F25A5A;
    }
    emit描述参数
    deleteEvent删除事件会传入删除前输入的值
    finishEvent完整输入后的事件会传入完成时输入的值
    deleteEvent(code) {
      // code 删除前输入的值
      this.wrong = false
    },
    finishEvent(code) {
      // code 完成时输入的值
      this.wrong = true
    },

    需要注意的是,props 中的 wrong 需要与两个emit 共同作用,用来在不同阶段控制输入框的状态。

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago