const util = require('../../utils/util.js')
timeClcik(){
let _this=this
if (!_this.data.isClicked) {
wx.showToast({
title: '验证码已发送',
})
//开始倒计时60秒
setTimeout(()=>{
_this.setData({
isClicked:true
})
util.settime(_this,60)
},1500)
}
},
function settime(_this,count){
if (count == 0) {
_this.setData({
ytext: '获取验证码',
isClicked:false
})
return
}
_this.setData({
isClicked:true,
ytext: count + '秒后重发',
})
setTimeout(function(){
count--
settime(_this, count)
}, 1000)
}
module.exports = {
settime: settime
}
<view>{{min}}:{{sec}}</view>//计时器,cycleTime为豪秒数
timerSec(cycleTime) {
var that = this
let intervalsec = null //倒计时函数
intervalsec = setInterval(function() {
cycleTime--
that.setData({
min: parseInt(cycleTime / 60) <10 ? '0' + parseInt(cycleTime / 60) : parseInt(cycleTime / 60),
sec: (cycleTime % 60) <10 ? '0' + (cycleTime % 60) : (cycleTime % 60),
})
if (cycleTime == 0) {
clearInterval(intervalsec)
}
}, 1000)
},
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)