1.0.10 • Published 1 year ago

vue3-auth-code-input v1.0.10

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

vue3-auth-code-input

这是一个基于 Vue 3 和 TypeScript 开发的验证码输入组件,适用于需要用户输入验证码的场景。它提供了灵活的配置选项,以适应不同的需求。

功能特点

  • 支持文本和数字类型验证码。
  • 自定义验证码长度。
  • 支持自定义宽度、高度、边框颜色等样式。
  • 支持发送验证码倒计时显示。
  • 可以自定义发送验证码按钮的文本和颜色。
  • 支持粘贴板自动填充验证码。
  • 支持自定义类名。
  • 支持自定义插槽。

line

card

demo

Get Start

npm install vue3-auth-code-input

Props 属性说明

属性名类型默认值描述
widthstring | number-组件宽度,单位:px
heightstring | number-组件高度,单位:px
v-model:codestring | number-验证码值
codeHeightstring | number40验证码输入框高度,单位:px
lengthnumber6验证码长度,最少4位
type'text' | 'number''text'验证码类型
titlestring-标题文本
contentTextstring-内容文本
cardbooleanfalse是否以卡片形式展示
borderColorstring#F1F1F1边框颜色
activeBorderColorstring#007AFF激活状态下的边框颜色
colorstring#333333文字颜色
fontSizestring | number12字体大小,单位:px
customNamestringinput-group-user自定义类名
customItemNamestringinput-item-user自定义验证码输入项的类名
sendTextstring发送验证码发送验证码按钮的文本
sendBtnColorstring#007AFF发送验证码按钮的颜色
sendCountDownnumber120发送验证码的倒计时
mobilestring-手机号,用于发送验证码,有值时显示传入手机号和按钮

slot

以下是组件提供的插槽及其描述:

NameDescription
header自定义组件头部区域。
content-text自定义内容文本区域。
send自定义发送验证码按钮区域。

event

事件名描述type
update:code当验证码输入更新时触发,返回最新的验证码值。(code: string \| number) => void
send点击发送验证码按钮时触发,返回手机号码。(mobile: string) => void

Ref 方法

当需要从父组件调用子组件的方法时,请使用 ref 引用。以下是可用的 ref 方法:

方法名描述参数
resetSendButton重置发送验证码按钮和倒计时,使其可以再次点击。newCountDown?: number (可选)

Example 示例

<template>
  <div>
    <sms-code ref="smsCodeRef" card title="温馨提示" content-text="请获取验证码后填写短信验证码。" mobile="159****8383" />
  </div>
</template>

<script lang="ts" setup>
import { ref } from 'vue';
import { SmsCode, type ISmsCodeComponentInstance  } from 'vue3-auth-code-input';

const smsCodeRef = ref<ISmsCodeComponentInstance | null>(null);

const resetTheButton = () => {
  smsCodeRef.value!.resetSendButton(60); // 60秒的新倒计时时间
};
</script>
1.0.10

1 year ago

1.0.9

1 year ago

1.0.7

1 year ago

1.0.5

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago