<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
相关推荐
漂流瓶jz3 小时前
Webpack如何实现万物皆可import?loader的使用/配置/手写实践ZC跨境爬虫3 小时前
跟着 MDN 学CSS day_41:显式轨道、隐式网格与区域命名放置修己xj4 小时前
告别手动存图!这款叫 Fatkun 的浏览器插件,简直是素材收集神器袋鼠云数栈4 小时前
从前端到基础设施,ACOS 如何打通企业全链路可观测AskHarries5 小时前
系统提示词、开发者指令和用户输入的优先级Moment5 小时前
长上下文会最终杀死 Rag 吗?qcx235 小时前
【系统学AI】25 论文导读 ①:两篇改变 AI 的开山之作——Attention Is All You Need & ReActkyriewen6 小时前
大文件上传最全指南:分片、断点续传、秒传,一篇就够了我叫黑大帅7 小时前
解决聊天页内部滚轮改为页面滚动问题郑洁文7 小时前
基于Python的Web命令执行漏洞自动化检测系统