爲了幫助開發者更便捷的使用支付寶小程序的短信驗證碼功能,特別是初學者更好的使用,榛子云短信特地開發了60秒倒計時插件,效果:
使用方法
1.引入插件countdown.js
var CountDown = require('../../utils/countdown.js');
2.在 onLoad 週期初始化
onLoad: function () { this.countdown = new CountDown(this); }
3.在獲取驗證碼的按鈕上增加captchaDisabled、captchaTxt 分別用於控制倒計時過程中是否可以點擊、倒計時秒數提示
<button onTap='getSmsCaptcha' disabled='{{captchaDisabled}}'>{{captchaTxt}}</button>
4. 調用start方法觸發倒計時
getSmsCaptcha(e) { this.countdown.start(); }
完整代碼下載:下載