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

微信小程序---验证码倒计时

实现效果

微信小程序如何实现获取验证码后倒计时效果?

完整代码

 

 wxml


<view class="password">
    <view class="header">
        <view>为了您的账户安全,需要验证您的手机</view>
        <view class="phone">186****4215 </view>
    </view>
    <view class="input">
        <input class="num" type="number" placeholder="输入验证码" bindinput="change" data-key="code" value="{{code}}"></input>
        <button class='btn' disabled='{{disabled}}' bindtap="getVerificationCode">{{time}}</button>
    </view>
    <view class="input">
        <input type="number" placeholder="输入新的密码" bindinput="change" data-key="password" value="{{password}}"></input>
    </view>
    <button class="button">确认</button>
</view>

wxss

/* pages/my/info/password/password.wxss */
.password {
    height: 100vh;
    background: #F4F6F7;
    padding-top: 52rpx;
    box-sizing: border-box;
}

.header {
    text-align: center;

}

.phone {
    margin-top: 22rpx;
    margin-bottom: 40rpx;
}

.input {
    width: 686rpx;
    height: 102rpx;
    background: #FFFFFF;
    border-radius: 8rpx;
    margin: 0 auto;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 30rpx 32rpx;
    box-sizing: border-box;
    margin-bottom: 24rpx;
}

.input .btn {

    height: 62rpx;
    margin-left: 25rpx;
    text-align: center;
    line-height: 30rpx;
    color: #00B652;
    background-color: #fff;
}

.button {
    width: 686rpx !important;
    height: 108rpx;
    background: #00B652;
    border-radius: 8rpx;
    line-height: 70rpx;
    color: #fff;
    margin-top: 56rpx;

}

.num {
    border-right: 1rpx solid #979797;
}

js

Page({

  data: {
    time: '获取验证码', //倒计时 
    currentTime: 60
  },

  onLoad(options) {

  },
  getCode: function () {
    var that = this;
    var currentTime = that.data.currentTime
    let interval = null
    interval = setInterval(function () {
      currentTime--;
      that.setData({
        time: currentTime + '秒'
      })
      if (currentTime <= 0) {
        clearInterval(interval)
        that.setData({
          time: '重新发送',
          currentTime: 60,
          disabled: false
        })
      }
    }, 1000)

  },

  getVerificationCode() {
    this.getCode();
    var that = this
    that.setData({
      disabled: true
    })
  },
})

相关文章:

  • Elasticsearch:运用 Python 实现在 Elasticsearch 上的向量搜索
  • 树的深度优先遍历与广度优先遍历
  • 大津法(最大类间方差法OTSU)
  • 搭建ELK分布式日志系统
  • 电子竞价是如何运作的?
  • TypeScript 学习之路 - 基础篇
  • 将路径中的“\\”换成“/”的方法
  • (一)Dubbo快速入门、介绍、使用
  • java-多线程,一个线程执行完毕,其他线程跳出运算-利用线程组ThreadGroup(子线程中执行当前线程组的interrupt方法)
  • 三分钟读懂什么是动作捕捉
  • Android—Surface,ViewRootImpl.relayoutWindow
  • <C++>详解string类
  • (一) springboot详细介绍
  • (一)UDP基本编程步骤
  • (附源码)spring boot公选课在线选课系统 毕业设计 142011
  • 【css3】浏览器内核及其兼容性
  • 【跃迁之路】【669天】程序员高效学习方法论探索系列(实验阶段426-2018.12.13)...
  • download使用浅析
  • HTTP传输编码增加了传输量,只为解决这一个问题 | 实用 HTTP
  • JAVA_NIO系列——Channel和Buffer详解
  • JavaScript对象详解
  • Just for fun——迅速写完快速排序
  • leetcode-27. Remove Element
  • OSS Web直传 (文件图片)
  • React-flux杂记
  • Redis字符串类型内部编码剖析
  • VUE es6技巧写法(持续更新中~~~)
  • 成为一名优秀的Developer的书单
  • 从输入URL到页面加载发生了什么
  • 对JS继承的一点思考
  • 给github项目添加CI badge
  • 前端攻城师
  • 如何邀请好友注册您的网站(模拟百度网盘)
  • 一天一个设计模式之JS实现——适配器模式
  • 由插件封装引出的一丢丢思考
  • puppet连载22:define用法
  • 扩展资源服务器解决oauth2 性能瓶颈
  • ​Linux·i2c驱动架构​
  • # Java NIO(一)FileChannel
  • %3cli%3e连接html页面,html+canvas实现屏幕截取
  • ( 用例图)定义了系统的功能需求,它是从系统的外部看系统功能,并不描述系统内部对功能的具体实现
  • (02)vite环境变量配置
  • (10)ATF MMU转换表
  • (6)STL算法之转换
  • (9)目标检测_SSD的原理
  • (Java数据结构)ArrayList
  • (附源码)springboot青少年公共卫生教育平台 毕业设计 643214
  • (附源码)计算机毕业设计SSM基于java的云顶博客系统
  • (六)软件测试分工
  • (每日持续更新)信息系统项目管理(第四版)(高级项目管理)考试重点整理第3章 信息系统治理(一)
  • (切换多语言)vantUI+vue-i18n进行国际化配置及新增没有的语言包
  • (十八)三元表达式和列表解析
  • (一) springboot详细介绍
  • (一一四)第九章编程练习
  • (转)chrome浏览器收藏夹(书签)的导出与导入