10分钟倒计时
<script>
export default {
name: "Home",
data() {
return {
time: {
D: '',
h: '',
m: '00',
s: '00',
},
}
}
methods: {
//倒计时
countTime: function () {
var that = this;
// debugger
//时间差
var leftTime = that.leftTime; //计算剩余的毫秒数
if (leftTime < 0) {
//标记结束按摩
return;
} else {
this.time.m = Math.floor(leftTime / 1000 / 60 % 60);//计算剩余的分钟
if (that.time.m < 10) {
that.time.m = "0" + that.time.m
}
that.time.s = Math.floor(leftTime / 1000 % 60);//计算剩余的秒数
if (that.time.s < 10) {
that.time.s = "0" + that.time.s
}
}
console.info(that.time.s);
that.leftTime -= 1000;
//递归每秒调用countTime方法,显示动态时间效果
setTimeout(that.countTime, 1000);
},
}
。。。