<button disabled="{{isClick}}" class="r_code" bindtap="getCountdown">{{timeCode}}</button>
/**
* 页面的初始数据
*/
data: {
navbarData: { // 组件所需的参数
showCapsule: true, //是否显示左上角图标
capsuleType: 'return', // 左上角图标类型 / return
title: '用户注册', //导航栏 中间的标题
},
timeCode: '获取验证码',
currentTime: 61, // 验证码倒计时秒数
isClick: false, // 获取验证码是否能点击
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
},
/**
* 获取验证码 倒计时60秒
*/
getCode() {
let that = this;
let currentTime = that.data.currentTime
let interval = setInterval(() => {
currentTime = currentTime - 1
that.setData({
timeCode: currentTime + '秒'
})
if (currentTime <= 0) {
clearInterval(interval)
that.setData({
timeCode: '重新发送',
currentTime: 61,
isClick: false
})
}
}, 1000)
},
/**
* 点击 获取验证码
*/
getCountdown() {
let that = this;
this.getCode();
that.setData({
isClick: true
})
},