小程序發送驗證碼倒計時
阿新 • • 發佈:2017-12-26
tex ont clas int true color url his nco
var countdown = 120; var settime = function (that) { if (countdown == 0) { that.setData({ codeText: ‘獲取驗證碼‘, code_time: ‘‘, isClick: false }) countdown = 120; return; } else { that.setData({ code_time: countdown+ ‘秒‘ }) countdown--; } setTimeout(function () { settime(that) }, 1000) } Page({ /** * 頁面的初始數據 */ data: { phone: ‘‘,//手機號 isClick: false, //是否點擊狀態,通過此狀態防止多次點擊 codeText: ‘獲取驗證碼‘, }, //獲取驗證碼 getCode: function (e) {var _this = this var click = _this.data.isClick //防止多次點擊 if (!click) { _this.setData({ isClick: true }) wx.request({ url: getApp().interFaceUrl._url + ‘Home/Login/get_code‘, method: ‘POST‘, data: { phone: _this.data.phone, types:1 }, header: { ‘content-type‘: ‘application/x-www-form-urlencoded‘ }, success: function (res) { if (res.data.status == ‘ok‘) { getApp().okInfo(‘驗證碼已發送‘); } else { getApp().errorInfo(‘驗證碼發送失敗‘); } _this.setData({ codeText: ‘重新發送‘ }) settime(_this); } }) } } })
小程序發送驗證碼倒計時