html里面:
<text class="time">支付剩余时间 {
{minutes<10 ? ('0' + minutes) : minutes }}:{
{seconds<10 ? ('0' + seconds) : seconds }}</text>
data里面定义变量:
minutes: 10, //分钟
seconds: 0, //秒数
在加载函数里面调用:
onLoad() {
this.countDownTimer()
},
在方法methods里面封装方法:
// 分秒倒计时
countDownTimer() {
let _this=this
let time = setInterval(function() {
if (_this.seconds === 0 && _this.minutes !== 0) {
_this.seconds = 59
_this.minutes --
} else if (_this.minutes === 0 && _this.seconds === 0) {
_this.seconds = 0
_this.minutes=0
clearInterval(time)
}else {
_this.seconds --
}
}, 1000)
},