Skip to content

LimeCodeInput 验证码输入框

一个验证码输入框组件,也可用作密码输入框,支持明文和密文显示,可自定义长度、间距和样式。

插件依赖:lime-sharedlime-style

文档链接

📚 组件详细文档请访问以下站点:

安装方法

  1. 在uni-app插件市场入口 中搜索并导入lime-code-input
  2. 首次导入可能需要重新编译

代码演示

基础使用

通过v-model双向绑定值

html
<l-code-input v-model="value"></l-code-input>
js
const value = ref('')

自定义长度

通过length属性来设置码长度

html
<l-code-input v-model="value"></l-code-input>
js
const value = ref('')

明文展示

mask 设置为 false 可以明文展示输入的内容,适用于短信验证码等场景。

html
<l-code-input v-model="value" :mask="false"></l-code-input>
js
const value = ref('')

提示信息

通过 info 属性设置提示信息,通过 error-info 属性设置错误提示,例如当输入六位时提示密码错误。

html
<l-code-input v-model="value" info="请输入验证码" :error-info="errorInfo"></l-code-input>
js
const value = ref('')
const errorInfo = ref('')

watch(value, (newVal) => {
    if (newVal.length == 6 && newVal != '123456') {
        errorInfo.value = '密码错误';
    } else {
        errorInfo.value = '';
    }
});

Vue2使用说明

本插件使用了composition-api,请按照官方教程配置。

关键配置代码(在main.js中添加):

js
// main.js
import Vue from 'vue'
import VueCompositionAPI from '@vue/composition-api'
Vue.use(VueCompositionAPI)

快速预览

导入插件后,可以直接使用以下标签查看演示效果:

html
<!-- 代码位于 uni_modules/lime-code-input/components/lime-code-input -->
<lime-code-input />

插件标签说明

  • l-code-input:验证码输入框组件
  • lime-code-input:演示标签

API文档

Props

参数说明类型默认值
v-model密码值string-
value密码值string-
info输入框下方文字提示string-
errorInfo输入框下方错误提示string-
length密码最大长度number6
gutter输入框格子之间的间距,如 20px 20rpx,默认单位为pxstring20rpx
mask是否隐藏密码内容booleantrue
focused是否已聚焦,聚焦时会显示光标booleanfalse
line是否使用下划线模式booleanfalse
borderColor描边色string-
width格子宽度string-
height格子高度string-
radius格子圆角string-
fontSize字体大小string-
activeBgColor激活格子背景色string-
activeBorderColor激活格子描边色string-
color文本色string-
bgColor格子背景色string-
cursorColor光标色string-
disabledKeyboard禁用系统键盘booleanfalse
disabledDot禁输入.booleantrue
insertAt指定位置插入符号,{index:2, symbol:'*'}object-
lastElementStyle最后一个元素样式string-
lastElementPlaceholder最后一个元素占位提示string-
lastElementPlaceholderStyle最后一个元素占位提示样式string-
typeinput的类型,参考input组件string-

Events

事件名说明回调参数
change值变化时触发event: string
focus聚焦时触发-
finish完成时event: string

Slots

插槽名说明回调参数
line线条active: boolean

主题定制

组件提供了下列CSS变量,可用于自定义样式。

变量名称默认值说明
code-input-height50px输入框整体高度
code-input-font-size20px输入文字大小
code-input-radius$spacer-tn输入框圆角半径
code-input-bg-color$gray-1输入框背景色
code-input-text-color$text-color-1输入文字颜色
code-input-info-color$text-color-3提示文字颜色
code-input-error-info-color$error-color错误提示颜色
code-input-dot-color$text-color-1密码点颜色
code-input-cursor-color$text-color-1光标颜色
code-input-dot-size10px密码点大小
code-input-info-font-size$font-size提示文字大小
code-input-cursor-width1px光标宽度
code-input-cursor-height40%光标高度比例
code-input-cursor-duration1s光标闪烁速度

支持与赞赏

如果你觉得本插件解决了你的问题,可以考虑支持作者:

支付宝赞助微信赞助

源代码

组件源码