wxml部分:
<input placeholder="请输入手机号" bindinput=“phoneInput”></input>
<button disabled="{{disabled}}" bindtap="getYzm">{{text}}</button>
js部分:
Page({
data: {
text: ‘获取验证码’,
currentTime: 61,
disabled: false,
phone: ‘’
},
phoneInput: function (e) {
this.setData({
phone: e.detail.value
})
},
getYzm: function() {
var that = this
that.setData({
disabled: true,
})
wx.showToast({
title: '短信验证码已发送',
icon: 'none',
duration: 2000
});
var currentTime = that.data.currentTime
var interval = setInterval(function() {
currentTime--;
that.setData({
text: currentTime + 's',
})
if (currentTime <= 0) {
clearInterval(interval)
that.setData({
text: '重新发送',
currentTime: 61,
disabled: false,
color: '#59b550'
})
}
}, 1000);
},