微信小程序倒計時60S
阿新 • • 發佈:2018-07-10
cati data- option -i disabled hat ear -- tap
<button class="code-b {{disabled?‘code-h‘:‘‘}}" disabled=‘{{disabled}}‘ data-id="2" bindtap="getVerificationCode">{{time}}</button>
var interval = null //倒計時函數 Page({ data: { time: ‘獲取驗證碼‘, //倒計時 currentTime: 60 }, }) getCode: function (options) { let that = this; let currentTime= that.data.currentTime console.log(1) interval = setInterval(function () { currentTime--; that.setData({ time: `重新獲取(${currentTime}s)` }) if (currentTime <= 0) { clearInterval(interval) that.setData({ time: ‘重新獲取‘, currentTime:60, disabled: false }) } }, 1000) }, getVerificationCode() { this.getCode(); let that = this that.setData({ disabled: true }) },
微信小程序倒計時60S