您当前的位置: 首页 > 解决方案

微信小程序 短信验证码登录 倒计时 setInterval

  • 作者: admin
  • 发布于 2018-09-15 13:59:26
  • 来源:  
  • 栏目:解决方案

导语: 需求:输入手机号 -> 点击获取验证码 -> 进入60s倒计时 短信验证码登录 data: { seconds: 0, // 读秒 timer: '' // 计时器 }, let that = this // 开

 需求:输入手机号 -> 点击获取验证码 -> 进入60s倒计时 

13.gif

短信验证码登录

 
  1. data: {
  2. seconds: 0, // 读秒
  3. timer: '' // 计时器
  4. },
  5. let that = this
  6. // 开始倒计时
  7. that.setData({
  8. seconds: 60,
  9. timer: setInterval(function(){
  10. let seconds = that.data.seconds
  11. that.setData({ seconds: seconds - 1 })
  12. if (that.data.seconds == 0) {
  13. // 读秒结束 清空计时器
  14. clearInterval(that.data.timer)
  15. }
  16. }, 1000)
  17. })
  18.  



温馨提示:这篇文章没有解决您的问题?欢迎添加微信:18948083295,有微信小程序专业人员,保证有问必答。转载本站文章请注明转自http://www.okeydown.com/(微信小程序网)。

  • 微信扫描二维码关注官方微信
  • ▲长按图片识别二维码
关注我们

微信小程序官方微信

栏目最新
栏目推荐
返回顶部