<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
相关推荐
极客密码7 小时前
感谢雷总!Mimo大模型价值¥659/月的 MAX 套餐,让我免费领到了!深念Y8 小时前
我明白为什么B站没法在浏览器开直播了——Windows Chrome推流踩坑全记录zhangxingchao8 小时前
AI应用开发七:可以替代 RAG 的技术Sun@happy8 小时前
现代 Web 前端渗透——基础篇(1)希冀1239 小时前
【CSS学习第十一篇】隔窗听雨眠9 小时前
doctype、charset、meta如何控制整个渲染流水线kyriewen9 小时前
写组件文档写到吐?我用AI自动生成Storybook,同事以后直接抄excel9 小时前
🧠 Prisma 表名大写 vs SQL 导出小写问题深度解析(附踩坑与解决方案)周淳APP9 小时前
【前端工程化原理通识:从源头到运行时的理论阐述】五点六六六10 小时前
你敢信这是非Native页面写出来的渐变效果吗🌝(底层原理解析