<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
相关推荐
对空六课11 小时前
支持注意力分析的热力图工具有哪些?Csvn12 小时前
Vue3 响应式与编译:依赖收集如何升级为节点级靶向更新星栈13 小时前
pnpm 12 升级实测Sirens.13 小时前
Java并发锁详解:六类锁策略与 synchronized 底层原理Ai-_Man14 小时前
您您这可以把Microsofat Copilot的多个会话比如说。左侧的多个会话一次性导出吗?不是单条会话里面的多次会对话。AI导出鸭特创数字科技15 小时前
一个纯本地运行的图片处理工具:压缩 / 裁剪 / 九宫格 / 圆角 / 滤镜 / 拼图 / 水印,终生使用IT_陈寒15 小时前
Vue的v-if和v-for混用居然是个天坑天衍四九-16 小时前
【无标题】广州华水科技16 小时前
2026年单北斗GNSS变形监测系统推荐榜单,解锁GNSS位移监测新高度xcyxiner16 小时前
DicomViewer24 修复编译bug(window test 失败)