to achieve the 60 seconds countdown after sending CAPTCHA, you can click again, but if you use setData to set the button button to disable, there is an asynchronous problem. When the countdown is 0, the crazy button can send several CAPTCHAs. How to solve this? the main code is as follows
.<button disabled="{{verifyBtnDisable}}" bindtap="sendVerify">{{verifyBtnText}}</button>
data:{
//
verifyBtnDisable:true,
verifyBtnText:""
}
//
sendVerify:function(){
let userTel = this.data.userTel.tel;
console.log(userTel);
console.log("");
wx.request({
url: "http://register.fd1.b.zhihui.hbraas.com/index.php?r=register/send-code",
data: {"Telephone":userTel},
method:"get",
dataType:"json",
success:res=>{
if (res.statusCode==200){
console.log("");
this.setData({
verifyBtnDisable: true
})
this.countDown();
}else{
console.log(res.statusCode);
console.log(res.data);
}
}
});
},
//
countDown:function(){
let num = 5;
let interval = setInterval(e=>{
if(num <= 0){
clearInterval(interval);
this.setData({
verifyBtnText: "",
verifyBtnDisable: false
});
}else{
num--;
this.setData({
verifyBtnText: num + "s"
});
}
},1000)
},