<template>
<div class="timer">
<p>{{ formatTime }}</p>
<button @click="startTimer" v-if="!isTiming">开始计时</button>
<button @click="stopTimer" v-else>停止计时</button>
</div>
</template>
<script>
export default {
data() {
return {
isTiming: false,
time: 0,
timer: null
}
},
computed: {
formatTime() {
const minutes = Math.floor(this.time / 60)
const seconds = this.time % 60
return `${minutes}:${seconds < 10 ? '0' : ''}${seconds}`
}
},
methods: {
startTimer() {
this.isTiming = true
this.timer = setInterval(() => {
this.time++
}, 1000)
},
stopTimer() {
this.isTiming = false
clearInterval(this.timer)
}
}
}
</script>
<style>
.timer {
text-align: center;
font-size: 24px;
margin-top: 50px;
}
</style>
在Uni-app中实现计时器效果
蜕变菜鸟2024-08-27 17:46
相关推荐
Flynt10 分钟前
我把热榜那篇"禁用 axios"逐条实测了一遍:结论大体对,坑在它没讲的地方Csvn1 小时前
bundle优化slongzhang_1 小时前
linux 递归删除源码文件|递归删除目录下 *.js,但排除 *.min.js北冥有鱼1 小时前
发版后动态路由点击报 `Failed to fetch dynamically imported module`」问题上的完整排查与修复过程静默回滚1 小时前
视频压到 25 MB 以内,码率要算、音轨要扣、余量要留用户37203749260181 小时前
把 10MB 中文语义模型塞进浏览器:STSB 做到教师模型的 93%,但线上 top1 只有 42%光锥智能2 小时前
海康机器人举行2026移动机器人新品发布会:箱式存拣升级,「明智」系列发布计算机魔术师2 小时前
Anthropic 上市文件最吓人的一幕,不是亏损 807 亿alsmile2 小时前
AI友好的可视化图形引擎自我革命:Meta2d.js 2.0 历时一年全新重写,性能与多人协作全面升级行思理2 小时前
Nginx 跨站请求(CORS)配置完全指南:从原理到生产实践