微信小程序发送手机验证码---倒计时
var currentTime = 59 //倒计时的事件(单位:s)
var interval = null //倒计时函数
Page({
data: {
time:59 //倒计时
},
onLoad:function(){
this.countdown();
},
// 倒计时
countdown:function(){
var that = this;
interval = setInterval(function () {
currentTime--;
that.setData({
time: currentTime
})
if (currentTime <= 0) {
clearInterval(interval)
currentTime = -1
}
}, 1000)
}
}