爲了幫助開發者更便捷的使用微信小程序的短信驗證碼功能,特別是初學者更好的使用,榛子云短信特意開發了60秒倒計時插件,效果:html
1.引入插件countdown.js小程序
var CountDown = require('../../utils/countdown.js');
複製代碼
2.在 onLoad 週期初始化
微信小程序
onLoad: function () {
this.countdown = new CountDown(this);
}複製代碼
3. 3.在獲取驗證碼的按鈕上增長captchaDisabled、captchaTxt 分別用於控制倒計時過程當中是否能夠點擊、倒計時秒數提示bash
<button class='codeBtn' bindtap='getSmsCaptcha' disabled='{{captchaDisabled}}'>{{captchaTxt}}</button>
複製代碼
4. 調用start方法觸發倒計時微信
getSmsCaptcha(e) {
this.countdown.start();
}複製代碼
完整代碼下載:下載ui
詳情參考: smsow.zhenzikj.com/bbs/questio…this