<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
相关推荐
一座古城29 分钟前
Claude Code 架构源码解析:AI 应用开发的范式跃迁K哥爬虫30 分钟前
【JS 逆向百例】Vaptcha V4 手势验证码逆向分析用户9210802628632 分钟前
复盘 AI Coding 工作台的流式链路:从 Sender 输入到 SSE 分流,再到 BubbleList 和右侧预览了不起的小明36 分钟前
SwiftMesh:本地 3D 模型查看器,加密交付 + 转盘录屏一站式搞定,开源免费默_笙38 分钟前
👍 我的代码被 ESLint 抓包了:单引号、var、没分号——全被当场点名搞个锤子哟39 分钟前
vue项目引入icon的问题树上有只程序猿43 分钟前
当低代码遇上AI,一个开发者的真实感悟郭邯1 小时前
从零手写一个 UA 解析工具:我用 AI 辅助开发,踩了这些坑oh,huoyuyan1 小时前
JS 动态网页抓不到?试试火车采集器网页抓取工具Heo1 小时前
怎么保证缓存和数据库一致性?