<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
相关推荐
moshuying几秒前
AI Coding 最大的 token 黑洞,可能根本不是 prompt红尘散仙2 分钟前
一行 `#[specta::specta]`,让 Tauri IPC 有类型lichenyang45323 分钟前
HarmonyOS HMRouter 接入记录:从普通 Tab Demo 到路由跳转木斯佳1 小时前
前端八股文面经大全:腾讯WXG暑期前端一面(2026-05-15)·面经深度解析canonical_entropy1 小时前
NOP Chaos Flux 架构演变史:从 AMIS 重写到现代低代码运行时张元清2 小时前
useEffect 之外:专门处理异步、深比较和 SSR 的 Effect Hook小小小小宇2 小时前
前端双Token机制无感刷新(二)XinZong2 小时前
OpenClaw 中最经典的 6 款skill,真正能进工作流的 skillszhangxingchao2 小时前
AI Agent 基础问题系统整理:从 LangChain、LangGraph、MCP 到 Agent 架构、记忆、工具调用与评估体系Moment3 小时前
AI 为什么总喜欢写防御性代码?