vue里面写个10分钟倒计时
时间: 2023-11-18 13:05:03 浏览: 177
<template>
<div>
<div>{{ minutes }}:{{ seconds < 10 ? '0' + seconds : seconds }}</div>
<button @click="startTimer">Start</button>
<button @click="stopTimer">Stop</button>
</div>
</template>
<script>
export default {
data() {
return {
minutes: 10,
seconds: 0,
timer: null
}
},
methods: {
startTimer() {
this.timer = setInterval(() => {
if (this.seconds === 0) {
if (this.minutes === 0) {
clearInterval(this.timer)
} else {
this.minutes--
this.seconds = 59
}
} else {
this.seconds--
}
}, 1000)
},
stopTimer() {
clearInterval(this.timer)
}
}
}
</script>
阅读全文