Skip to content

CodeInput 验证码 / 车牌号输入

用于手机短信验证码、支付交易密码以及车牌号码录入的多格拆分输入控件,支持新能源车牌专属插槽与自定义虚拟键盘弹起。


代码示例

1. 车牌号九宫格模式 (Car Plate Grid)

设置 mode="car" 开启车牌号输入框形态。默认生成 8 位框(7 位燃油车 + 第 8 位 + 新能源 虚线插槽与绿色徽标),点击格框自动弹起车牌号专用键盘。

vue
<template>
  <mu-code-input v-model="carNumber" mode="car" @finish="handleFinish" />
</template>

<script setup>
import { ref } from 'vue'
const carNumber = ref('京A88888')
const handleFinish = (val) => {
  console.log('车牌号输入完成:', val)
}
</script>

2. 基础 4 位验证码 (Basic)

使用 v-model 绑定当前输入的字符串,使用 length 指定验证码位数(如 4 位)。输入完成后自动触发 @finish 事件。

vue
<template>
  <mu-code-input v-model="code" :length="4" @finish="handleFinish" />
</template>

<script setup>
import { ref } from 'vue'
const code = ref('')
const handleFinish = (val) => {
  console.log('验证码输入完成:', val)
}
</script>

3. 6 位密码/掩码模式 (Mask Password)

设置 mode="password"mask 开启密文黑点显示,常用于支付密码与验证码。

vue
<template>
  <mu-code-input v-model="password" :length="6" mode="password" />
</template>

4. 下划线形态 (Underline)

设置 shape="underline" 切换为极简下划线分割样式。

vue
<template>
  <mu-code-input v-model="code" :length="4" shape="underline" />
</template>

API 属性说明 (Props)

参数名说明类型可选值默认值
v-model当前输入的验证码/车牌号字符串String-''
mode组件输入模式Stringcode | password | car'code'
length验证码位数格数 (car 模式默认 8 位)Number-4
shape格框外观形态Stringradius | square | round | underline'radius'
mask是否使用圆点密文遮罩隐藏Booleantrue | falsefalse
useVirtualKeyboard是否启用底部自定义虚拟键盘Booleantrue | falsefalse
autoFocus是否自动聚焦调出键盘Booleantrue | falsefalse
keyboardTitle虚拟键盘顶部标题String-''

事件说明 (Events)

事件名说明回调参数
change每次输入字符改变时触发(value: String)
finish当输入位数达到 length 完成时触发(value: String)
update:modelValue双向绑定更改变(value: String)

基于 MIT 协议开源发行

H5 模拟器 (code-input)☀️🔄