更新记录

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

Vue2 Vue3
?
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

app-android app-ios
? ?
H5-Safari Android Browser 微信浏览器(Android) QQ浏览器(Android) Chrome IE Edge Firefox PC-Safari
? ? ? ? ? ? ? ? ?

线上预览

image

使用方法

<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>

隐私、权限声明

1. 本插件需要申请的系统权限列表:

2. 本插件采集的数据、发送的服务器地址、以及数据用途说明:

插件不采集任何数据

3. 本插件是否包含广告,如包含需详细说明广告表达方式、展示频率:

许可协议

MIT协议

使用中有什么不明白的地方,就向插件作者提问吧~ 我要提问