微信小程序-倒计时

wxml
 
<view class='identifyingCode'>
<input bindinput="bindInput" type="number" bindfocus='textAnimation'/>
<button class='changeType' bindtap='getIdentifyingCode' style='display:{{showTiming==false?"":"none"}}'>获取验证码</button>
<button class='changeType' disabled='{{disabled}}' style='display:{{showTiming==false?"none":""}}'>{{currentTime}}秒后重发</button>
</view>
 
js
 
getIdentifyingCode(){
this.setData({
showTiming:!this.showTiming,
})

let that = this
let currentTime = that.data.currentTime
var myInterval = setInterval(function () {
currentTime--;
that.setData({
currentTime: currentTime
})
if (currentTime <= 0) {
clearInterval(myInterval)
that.setData({
showTiming:false,
disabled:false,
currentTime:60
})
}
}, 1000)

}
原文地址:https://www.cnblogs.com/lipuqing180906/p/9602634.html