<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
相关推荐
xiaofeichaichai1 小时前
Webpack问心无愧05132 小时前
ctf show web入门111唐某人丶2 小时前
模型越来越强,我们还需要 Agent 工程吗?—— 从价值重估到 Harness 实践智码看视界2 小时前
现代Web开发基础:全栈工程师的起航点JS菌2 小时前
手写一个 AI Agent 全栈项目:从沙箱执行到子智能体的完整实现excel3 小时前
HLS TS 文件损坏的元凶:Git 提交与拉取Aphasia3114 小时前
https连接传输流程徐小夕4 小时前
万字长文!千万级文档 RAG 知识库系统落地实践threelab4 小时前
Three.js 物理模拟着色器 | 三维可视化 / AI 提示词