欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 科技 > 能源 > 在Uni-app中实现计时器效果

在Uni-app中实现计时器效果

2024/10/24 17:21:10 来源:https://blog.csdn.net/guaiguail/article/details/141418665  浏览:    关键词:在Uni-app中实现计时器效果
<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 % 60return `${minutes}:${seconds < 10 ? '0' : ''}${seconds}`}},methods: {startTimer() {this.isTiming = truethis.timer = setInterval(() => {this.time++}, 1000)},stopTimer() {this.isTiming = falseclearInterval(this.timer)}}
}
</script><style>
.timer {text-align: center;font-size: 24px;margin-top: 50px;
}
</style>

原博:在Uni-app中实现计时器效果_uniapp 计时器-CSDN博客

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com