更新记录
1.0.5(2024-06-26)
修复因text-align导致的input显示问题
1.0.4(2024-06-26)
更新隐藏input长度过短显示数字BUG
1.0.3(2024-06-19)
修复插件取消聚焦时的动画隐藏问题
查看更多
平台兼容性
uni-app
app-vue |
app-nvue |
app-android |
app-ios |
? |
? |
? |
? |
H5-Safari |
Android Browser |
微信浏览器(Android) |
QQ浏览器(Android) |
Chrome |
IE |
Edge |
Firefox |
PC-Safari |
? |
? |
? |
? |
? |
? |
? |
? |
? |
微信小程序 |
支付宝小程序 |
百度小程序 |
字节小程序 |
QQ小程序 |
钉钉小程序 |
快手小程序 |
飞书小程序 |
京东小程序 |
? |
? |
? |
? |
? |
? |
? |
? |
? |
uni-app x
H5-Safari |
Android Browser |
微信浏览器(Android) |
QQ浏览器(Android) |
Chrome |
IE |
Edge |
Firefox |
PC-Safari |
? |
? |
? |
? |
? |
? |
? |
? |
? |
线上预览
![image](https://masteryi-localhost.oss-cn-hangzhou.aliyuncs.com/uni-app/yi-code-qrcode.png)
使用方法
<yi-code @onComplete="complete" @onChange="change"></yi-code>
参数
属性 |
类型 |
说明 |
默认值 |
width |
number |
宽度 rpx |
500 |
maxlength |
number |
验证码长度 |
6 |
focus |
boolean |
是否自动聚焦 |
true |
type |
pane、line |
组件风格支持block方框, dashed 虚线方框,line 线 |
block |
inputType |
text、number |
输入框类型 支持text、number |
number |
@onComplete |
(code: string) |
输入长度===maxlength时的完成回调onComplete |
null |
@onChange |
(code: string) |
code值变更回调onChange |
null |
个人博客
www.masteryi.cn
示例代码
<template>
<view class="page">
<view class="card">
<view class="title">block</view>
<view class="body">
<yi-code :width="600" @onComplete="complete" @onChange="change"></yi-code>
</view>
</view>
<view class="card">
<view class="title">dashed</view>
<view class="body">
<yi-code :focus="false" :maxlength="5" type="dashed"></yi-code>
</view>
</view>
<view class="card">
<view class="title">line</view>
<view class="body">
<yi-code :focus="false" :maxlength="4" type="line"></yi-code>
</view>
</view>
<view class="card">
<view class="title">dashed - hide</view>
<view class="body">
<yi-code :focus="false" hide="*" :maxlength="5" type="dashed" @onComplete="complete"></yi-code>
</view>
</view>
</view>
</template>
<script>
// 注意测试案例的时候 focus只保持一个自动聚焦, 其他设置false,防止调试输入不了;
// 刚导入插件请重启一下项目防止缓存未加载
export default {
data() {
return {
}
},
onLoad() {
},
methods: {
complete(code){
console.log(`complete:${code}`);
},
change(code){
console.log(`change:${code}`);
}
}
}
</script>
<style lang="scss">
.page {
display: flex;
flex-wrap: wrap;
.card{
width: 720rpx;
margin: 30rpx auto;
border: 1px solid #f0f0f0;
border-radius: 12rpx;
.title{
font-size: 14px;
text-align: center;
line-height: 30px;
border-bottom: 1px solid #f0f0f0;
}
.body{
display: flex;
align-items: center;
justify-content: center;
height: 150rpx;
}
}
}
</style>