vue里面写个10分钟倒计时
时间: 2023-11-18 14:05:03 浏览: 144
基于vue的过年倒计时的代码
<template>
<div>
<h1>{{ minutes }}:{{ seconds }}</h1>
</div>
</template>
<script>
export default {
data() {
return {
minutes: 10,
seconds: 0
}
},
mounted() {
this.startCountdown()
},
methods: {
startCountdown() {
setInterval(() => {
if (this.seconds === 0) {
if (this.minutes === 0) {
clearInterval()
// do something when countdown is finished
} else {
this.minutes--
this.seconds = 59
}
} else {
this.seconds--
}
}, 1000)
}
}
}
</script>
阅读全文