微信小程序点击发送短信验证(60秒倒计时)

 

 /**   * 执行计时,60s后可以重新发送短信验证码   */  countdown: function() {    var nsecond = 60;    var that = this;    var appCount = setInterval(function() {      nsecond -= 1;      that.setData({        second: nsecond      })      if (nsecond 1) {        clearInterval(appCount);        //取消指定的setInterval函数将要执行的代码         that.setData({          send: true,          second: 60,          reSend: false        })      }      console.log(nsecond);    }, 1000);  }

注意:声明变量的时候是 var  appCount,这在当前页面是全局的,方便在其它位置清除它

   if (appCount) {      clearInterval(appCount);    }

需要在 Page.data 中定义 second:

Page({  data: {    send: false,    second: 60,    reSend: true  }

send 和 reSend 是用来控制页面元素显示的。

TAG标签: 微信小程序微信短信验证码收不到

http://www.xiaochengxub.com/read-101502.html