当前位置: 首页 > news >正文

【uniapp】六格验证码输入框实现

效果图

在这里插入图片描述

代码实现

<view><view class="tips">已发送验证码至<text class="tips-phone">{{ phoneNumber }}</text></view><view class="code-input-wrap"><input class="code-input" v-model="codeNumber" type="number" :adjust-position="false" :auto-blur="true" maxlength="6" @input="handleInputClick" /><view class="code-list"><block v-for="(item, index) in 6" :key="index"><view :class="['code-list-item', codeNumber.length == index ? 'active-item' : '']">{{ codeNumber[index] }}</view></block></view></view><view class="resending" v-if="isSending">{{ '重新发送(' + counter + 's)' }}</view><view class="normal" v-else @click="handleResend">重新发送</view>
</view>
data() {return {phoneNumber: '',codeNumber: '',isPhoneValid: false,isCodeValid: false,isSending: false, // 验证码是否在发送中// 计时器对象timer: null,// 倒数60秒counter: 60}
},
methods: {// 输入验证码handleInputClick(e) {let val = e.detail.valuethis.codeNumber = valif (val && val.length == 6) {this.isCodeValid = true} else {this.isCodeValid = false}},// 获取验证码sendSmsCode() {if (this.isPhoneValid) {// 判断手机号格式是否符合要求if (!/^1[3456789]\d{9}$/.test(this.phoneNumber)) {uni.showToast({title: '手机号格式不正确',icon: 'none'})return false}// 判断复选框if (!this.isChecked) {this.showTips = truereturn false}// 调用接口,此处代码省略······}},// 倒计时countDown() {this.counter = 60this.isSending = truethis.timer = setInterval(() => {this.counter--if (this.counter < 0) {this.reset()}}, 1000)},// 重置倒计时reset() {this.isSending = falseif (this.timer) {clearInterval(this.timer)this.counter = 60this.timer = null}},// 重新发送handleResend() {this.codeNumber = ''this.sendSmsCode()}        
}
.tips {font-size: 28rpx;font-weight: 400;line-height: 36rpx;.tips-phone {font-weight: bold;margin-left: 20rpx;}
}// 验证码输入
.code-input-wrap {margin: 40rpx 0;position: relative;height: 100rpx;.code-input {position: absolute;left: 0;top: 0;height: 100rpx;width: 100%;opacity: 0;z-index: 99;outline: none;}.code-list {position: absolute;left: 0;top: 0;width: 100%;height: 100rpx;display: flex;justify-content: space-between;.code-list-item {// flex: 1;width: 90rpx;height: 100rpx;background: #ffffff;border-radius: 16rpx;font-size: 36rpx;font-weight: 700;color: #adb3ba;line-height: 100rpx;text-align: center;margin-right: 10rpx;z-index: 5;box-sizing: border-box;}.code-list-item:last-child {margin-right: 0;}.active-item {border: 2rpx solid #ff466d;}}
}
.resending {font-size: 28rpx;font-weight: 500;line-height: 36rpx;margin-bottom: 60rpx;color: #a6acb2;
}
.normal {font-size: 28rpx;font-weight: 500;line-height: 36rpx;margin-bottom: 60rpx;color: #333;
}
http://www.lryc.cn/news/227011.html

相关文章:

  • 【react hook】在react hook组件中,使用Antd Table组件,columns数据异步获取,list数据更新但没有rerender解决办法
  • ChatGPT的图识别来了
  • java Stream编程笔记
  • 顶顶通语音识别使用说明
  • 重磅发布 OpenAI 推出用户自定义版 ChatGPT
  • Java 幼儿园(20231111)读取 json 文件
  • 云计算、大数据技术的智慧工地,实现对建筑工地实时监测、管理和控制的一种新型建筑管理方式
  • 功能案例 -- 通过开关,改变白天和黑夜
  • Linux编写一个极简版本的Shell
  • 亚马逊云AI应用科技创新下的Amazon SageMaker使用教程
  • Eigen:旋转向量(Angle-Axis)转换为四元素和旋转矩阵
  • C#8.0本质论第十二章--泛型
  • Python与ArcGIS系列(七)自动化打印地图
  • 基于STM32单片机抢答器设计
  • 冯·诺伊曼体系结构--操作系统
  • IDEA插件开发--持久化配置信息方案
  • Vscode禁止插件自动更新
  • Zookeeper篇---第六篇
  • mysql数据库存储过程之游标(光标cursor)
  • 「帝国风暴兵」加入 The Sandbox,推出真实的全新人物化身系列和体验!
  • asp.net员工管理系统VS开发sqlserver数据库web结构c#编程包括出差、请假、考勤
  • C++套接字库sockpp介绍
  • Mac M2开发环境安装
  • Linux各种版本安装详细步骤和root密码破解
  • Netty - 回顾Netty高性能原理和框架架构解析
  • uni-app——項目day01
  • 【Java、MongoDB】程序控制非关系数据库
  • MySQL查询时间处理相关函数与方法实践笔记
  • springboot全局拦截sql异常
  • AlGaN/GaN HFET 五参数模型