效果图是这样的(如下图):
validCode.vue文件代码如下:
<!--
自定义验证码输入、密码输入使用
使用方法:
maxlength:输入最大长度
isPwd:是否是密码模式
@finish:回调函数
<validcode :maxlength="4" :isPwd="false" @finish="finish"></validcode>
-->
<template>
<view class="code-area">
<view class="flex-box">
<input
:value="val"
type="number"
focus="true"
:maxlength="maxlength"
class="hide-input"
@input="getVal"
/>
<view v-bind:class="['item', { active: codeIndex == 1 }]">
<view class="line"></view>
<block v-if="isPwd && codeArr.length >= 1">
<text class="dot">.</text>
</block>
<block v-else> {
{ codeArr[0] ? codeArr[0] : ''}}</block>
</view>
<view v-bind:class="['item', { active: codeIndex == 2 }]">
<view class="line"></view>
<block v-if="isPwd && codeArr.length >= 2">
<