data: {
count: 60,
mobile: '',
code: '获取验证码',
},
textCode: function () {
let that = this
if (!(/^1[3456789]\d{9}$/.test(this.data.mobile))) {
wx.showToast({
title: '输入手机号有误',
icon: 'none',
duration: 2000
})
return;
}
if (that.data.code !== '获取验证码') {
return
}
const countDown = setInterval(() => {
if (that.data.count <= 0) {
that.setData({
count: 60,
code: '获取验证码'
})
clearInterval(countDown)
return
}
that.data.count--
that.setData({
count: that.data.count,
code: that.data.count < 10 ? `请等待0${that.data.count}s` : `请等待${that.data.count}s`
})
}, 1000);
that.textCode_http()
},