点击获取验证码后 倒计时不会启动 ,短信验证码正常能接收 ,下面是前端js
// 获取真实姓名 手机号
getData(){
let that = this;
wx.showLoading({
mask: true
})
wx.request({
url: app.d.WEB_URL +"/api/user/index",
method: "POST",
header: {
"Content-Type": "application/x-www-form-urlencoded"
},
data: {
token:wx.getStorageSync('token')
},
success(res) {
console.log(res)
wx.hideLoading();
if(res.data.code=="103"){
app.nologin()
}else if (res.data.code == 1) {
that.setData({
mobile:res.data.data.mobile,
name:res.data.data.realname,
})
if(res.data.data.mobile!=''){
that.setData({
mobileDisbled:true
})
}
if(res.data.data.realname!=''){
that.setData({
nameDisbled:true
})
}
}else{
wx.showToast({
title: res.data.msg,
mask: true,
icon: 'none'
})
}
}
})
},
// 图片一直旋转动画
refreshList: function () {
var that = this
// 重新获取验证码
that.setData({
pintuShow:'none'
})
setTimeout(function(){
that.setData({
pintuShow:'block'
})
},100)
},
mobileInput(e) {
this.setData({
mobile: e.detail.value
})
},
nameInput(e) {
this.setData({
name: e.detail.value
})
},
codeInput(e) {
this.setData({
code: e.detail.value
})
},
codeTopt(){
if(this.data.mobile==''){
wx.showToast({
title: '请输入联系方式',
duration: 2000,
icon: 'none'
});
}else {
this.setData({
pintuShow:'block',
ptshow:true,
})
}
},
onMyEvent: function (e) {
//通过事件接收插件数据:中奖id与剩余抽奖次数
console.log(e.detail)
if(e.detail.result=='ok'){
this.countDown();
this.setData({
pintuShow:'none',
ptshow:false,
is_hui :''
})
}else {
this.setData({
pintuShow:'none',
ptshow:false,
})
}
},
codeBtn() {
var that = this
wx.request({
url: app.d.WEB_URL +"/api/index/sendMsg",
method: 'post',
data: { token:wx.getStorageSync('token'),mobile: that.data.mobile},
header: {
'Content-Type': 'application/x-www-form-urlencoded'
},
success: function (res) {
console.log(res)
wx.hideLoading()
if (res.data.code == 1) {
wx.showToast({
title: res.data.msg,
duration: 2000,
icon: 'none'
});
that.setData({
disabled: true,
})
that.countDown();
} else {
wx.showToast({
title: res.data.msg,
duration: 2000,
icon: 'none'
});
}
},
fail: function () {
// fail
wx.showToast({
title: '网络异常!',
duration: 2000,
icon: 'none',
icon: 'none'
});
}
});
},
// 倒计时
countDown() {
//倒计时
let time = 60;
let timer = setInterval(() => {
if (time == 0) {
clearInterval(timer);
var codetext = '获取验证码';
this.setData({
disabled: true,
codetext: codetext,
})
} else {
this.setData({
disabled: false,
codetext: time + '秒',
})
time--
}
}, 1000)
},
```