<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
相关推荐
天平8 小时前
油猴脚本创建webworker踩坑记录原则猫9 小时前
前端基础大厦陈随易11 小时前
编程语言级别的Skill市场,AI Agent 的未来形态SoaringHeart11 小时前
Flutter进阶:基于 EasyRefresh 的下拉刷新封装 n_easy_refresh_mixin.dartIT_陈寒13 小时前
Vite的热更新突然不香了,排查三小时差点砸键盘子兮曰14 小时前
Agency-Agents 深度解析:400+ AI 专家的"梦之队"如何重塑开发工作流山河木马14 小时前
渲染管线-计算得到gl_Position(顶点着色器)之后续GPU流程竹林81814 小时前
用 The Graph 查询链上数据实战:从手搓 RPC 到 Subgraph,我的 NFT 项目数据加载快了 10 倍妙码生花15 小时前
从 PHP 到 AI + Golang,程序员自救转型手记(十九):点选验证码代码逐行目检Awu122715 小时前
⚡从零开发 Agent CLI(五)实现一个可治理、可扩展的工具系统