wxml
<button style="color:{{color}}" disabled="{{disabled}}" bindtap="sendCode">{{text}}</button>
data
data:{
disabled: false,
text: "获取验证码",
color: "#06AE56",
time: 60
}
js
sendCode(){
var timer = setInterval(() => {
this.setData({
disabled: true,
color: "#cccccc",
time: this.data.time - 1,
text: this.data.time + 's后重发',
})
if (this.data.time < 0) {
clearInterval(timer)
this.setData({
disabled: false,
color: "#06AE56",
time: 60,
text: '获取验证码',
})
}
}, 1000)
}