Skip to content

CodeInput 验证码输入框

介绍

一般用于验证用户短信验证码的场景,该组件参考了 uview-ui 的 验证码输入框

基础用法

html
<template>
  <nut-code-input v-model="value"></nut-code-input>
</template>
ts
const value = ref("");

横线模式

html
<template>
  <nut-code-input v-model="value" mode="line"></nut-code-input>
</template>

设置长度

html
<template>
  <nut-code-input v-model="value" :maxlength="6"></nut-code-input>
</template>

横线间距

html
<template>
  <nut-code-input v-model="value" :space="0"></nut-code-input>
</template>

调整颜色

html
<template>
  <nut-code-input
    v-model="value"
    hairline
    custom-color="#f56c6c"
    border-color="#f56c6c"
  ></nut-code-input>
</template>

事件

html
<template>
  <nut-code-input
    @change="onChange"
    @finish="onFinish"
  ></nut-code-input>
</template>
ts
function onChange(value: string) {
  console.log("内容改变", value);
}

function onFinish(value: string) {
  console.log("输入结束", value);
}

API

Props

参数说明类型可选值默认值
v-model输入值string--
adjust-position键盘弹起时,是否自动上推页面boolean-true
maxlength最大输入长度number / string-4
dot是否用圆点填充boolean-false
mode选择样式为边框或者横线stringbox / linebox
hairline是否细边框boolean-false
space字符间的距离number / string-10
focus是否自动获取焦点boolean-false
bold字体是否加粗boolean-false
custom-color字体颜色string-#606266
font-size字体大小(单位:px)number / string-18
size输入框的大小(单位:px)number / string-35
disabled-keyboard禁止点击输入框唤起系统键盘boolean-false
border-color边框和线条颜色string-#c9cacc
disabled-dot是否禁止输入 . 符号boolean-true

Events

事件名说明类型
change输入内容发生改变时触发(value: string) => void
finish输入字符个数达到 maxlength 时触发(value: string) => void

主题定制

样式变量

组件提供了下列 CSS 变量,可用于自定义样式,使用方法请参考 ConfigProvider 组件

名称默认值
--nut-code-input-cursor-widthvar(--nut-code-input-cursor-width)
--nut-code-input-cursor-heightvar(--nut-code-input-cursor-height)
--nut-code-input-cursor-animation-duration1s
--nut-code-input-cursor-animation-namenut-cursor-flicker
--nut-code-input-content-colorvar(--nut-code-content-color)

MIT Licensed