<template>
<div>
<div>
{
{ t_Minutes }} : {
{ t_Seconds }} : {
{ t_Milliseconds }}
</div>
<div v-if="time <= 0">时间到了!</div>
</div>
</template>
<script>
export default {
data() {
return {
time: 180,
};
},
computed: {
t_Minutes() {
const minutes = Math.floor(this.time / 60);
return minutes.toString().padStart(2, '0');
},
t_Seconds() {
const seconds = Math.floor(this.time % 60);
return seconds.toString().padStart(2, '0');
},
t_Milliseconds() {
const milliseconds = Math.floor((this.time % 1) * 100);
return milliseconds.toString().padStart(2, '0');
},
},
mounted() {
setInterval(this.updateTime, 1);
},
methods: {
updateTime() {
if (this.time > 0) {
this.time -= 0.004;
}
},
},
};
</script>
vue.js写一个三分钟的倒计时,格式为02:59:99
猜你喜欢
转载自blog.csdn.net/m0_66675766/article/details/130321484
今日推荐
周排行