微信小程序“获取验证码”button倒计时
获取验证码→倒计时(button禁用)→重新发送
代码片段(https://developers.weixin.qq.com/s/ug9qiymt7G79)
js
const app = getApp()
Page({
data: {
disabled: false,
codename: '获取验证码'
},
onLoad: function () {
},
//button
getVerificationCode: function () {
var that = this
var num = 5;
that.setData({
codename: num + "s"
})
var timer = setInterval(function () {
num--;
if (num <= 0) {
clearInterval(timer);
that.setData({
codename: '重新发送',
disabled: false
})
} else {
that.setData({
codename: num + "s",
disabled: true
})
}
}, 1000)
}
})