Skip to content

H5预览

APP下载

InputOtp 验证码输入

cl-input-otp 是一个验证码输入组件,用于输入一次性密码(OTP)或验证码,支持自定义位数、自动聚焦等功能,提供良好的用户输入体验。

参数

参数说明类型可选值默认值
pt样式穿透配置PassThrough
modelValue当前输入的验证码值string
autofocus是否自动聚焦booleanfalse
length验证码位数number4
disabled是否禁用组件booleanfalse
inputType输入类型string"number"'number'

事件

事件名称说明回调参数
done验证码输入完成时触发

PassThrough

样式穿透配置允许您自定义组件内部各个元素的样式,实现更灵活的外观定制。

参数说明类型
className组件根元素样式string
list输入框列表容器配置PassThroughProps
item单个输入框配置PassThroughProps
cursor光标指示器配置PassThroughProps
value输入值显示配置PassThroughProps

示例

基础用法

html
<cl-input-otp></cl-input-otp>

自动聚焦

设置 autofocus 属性,组件渲染后自动聚焦到第一个输入框:

html
<cl-input-otp autofocus></cl-input-otp>

自定义位数

通过 length 属性设置验证码位数,适用于不同长度的验证码场景:

html
<cl-input-otp :length="6"></cl-input-otp>

自定义样式

通过 PassThrough 配置自定义组件外观,实现个性化的视觉效果:

vue
<cl-input-otp
  :pt="{
    item: {
      className: '!bg-sky-100',
    },
    value: {
      className: '!text-sky-700',
    },
  }"
></cl-input-otp>