微信小程序短信验证码倒计时
getCode: function (options) {
this.setData({time: !this.data.time})//获取验证码按钮样式改变
var that = this;
var currentTime = that.data.currentTime;//获取data中的currentTime也就是倒计总时长60s
var interval = setInterval(function () {
that.setData({count: (currentTime - 1) + 's'})//调用时从初始数据60到59
currentTime--;
if (currentTime < 0) {
clearInterval(interval);//清除计时器
that.setData({
time: false,
currentTime: 60,
count: '60s',
})
}
}, 1000)
console.log(interval);
},