首先定义data里currentTime的初始时间
然后把下面代码写在点击的事件中
if (that.data.xianshi == true) {//这个是自己定义遮罩层的显示隐藏
var interval = null
var currentTime = that.data.currentTime;
that.setData({
time: currentTime + 's'
})
interval = setInterval(function() {
that.setData({
time: (currentTime - 1) + 's'
})
currentTime--;
if (currentTime <= 0) {
clearInterval(interval)
that.setData({
time: '重新获取',
currentTime: 5,
xianshi: false
})
}
}, 1000)
} else {
}
}