用vue怎样写倒计时按钮,代码是什么
Admin 2022-08-06 群英技术资讯 706 次浏览
实现效果:
1.点击开始按钮启动计时
2.点击重置按钮计时恢复到00:00:00
3.点击暂停按钮暂停计时
Vue代码:
<template> <div> <div class="timeContainer">{{ time }}</div> <a-button style="margin-right: 20px" type="primary" @click="start" >开始</a-button > <a-button style="margin-right: 20px" type="primary" @click="reset" >重置</a-button > <a-button type="primary" @click="end">暂停</a-button> </div> </template> <script> export default { data() { return { flag: null, hour: 0, minute: 0, second: 0, time: "00:00:00", }; }, methods: { //开始计时 start() { this.flag = setInterval(() => { this.second = this.second + 1; if (this.second >= 60) { this.second = 0; this.minute = this.minute + 1; } if (this.minute >= 60) { this.minute = 0; this.hour = this.hour + 1; } this.time = this.complZero(this.hour) + ":" + this.complZero(this.minute) + ":" + this.complZero(this.second); }, 1000); }, //重新计时 reset() { window.clearInterval(this.flag); this.hour = 0; this.minute = 0; this.second = 0; this.time = "00:00:00"; }, //暂停计时 end() { this.flag = clearInterval(this.flag); }, //补零 complZero(n) { return n < 10 ? "0" + n : "" + n; }, }, }; </script> <style> .timeContainer { font-size: 40px; margin-bottom: 10px; } </style>
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:mmqy2019@163.com进行举报,并提供相关证据,查实之后,将立刻删除涉嫌侵权内容。
猜你喜欢
jQuery中删除样式的方法是什么?对于删除样式我们可以利用removeAttr()方法和removeClass()方法,那么这两个方法具体是如何删除样式的呢?接下来我们一起来学习一下。
今天给大家分享的是React Hooks使用要注意问题的内容,本文有实例和详细注释供大家参考,对大家理解Hooks的使用有一定的帮助,接下来跟随小编一起看看吧。
这篇我们来了解Node.js中puppeteer库如何安装和使用,以及能用做什么?文中的介绍很详细,有具体示例供大家参考,对大家学习和了解puppeteer库的使用有帮助,感兴趣的朋友就继续往下看吧。
vue项目在本地构建后,每次热更新都会卡在 75 advanced module optimization 的地方不动了。很影响开发效率有木有,网上一搜给的方案(babel-plugin-dynamic-import-node)试了下各种报错,要么说版本问题,要么说引入文件的方式不对,要么说webpack的配置不对,然
这篇文章主要为大家介绍了python的函数,具有一定的参考价值,感兴趣的小伙伴们可以参考一下,希望能够给你带来帮助
成为群英会员,开启智能安全云计算之旅
立即注册Copyright © QY Network Company Ltd. All Rights Reserved. 2003-2020 群英 版权所有
增值电信经营许可证 : B1.B2-20140078 粤ICP备09006778号 域名注册商资质 粤 D3.1-20240008