用vue怎样写倒计时按钮,代码是什么
Admin 2022-08-06 群英技术资讯 919 次浏览
这篇文章给大家介绍了“用vue怎样写倒计时按钮,代码是什么”的相关知识,讲解详细,步骤过程清晰,有一定的借鉴学习价值,因此分享给大家做个参考,感兴趣的朋友接下来一起跟随小编看看吧。实现效果:
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进行举报,并提供相关证据,查实之后,将立刻删除涉嫌侵权内容。
猜你喜欢
js中的this关键字平时在开发中使用时倒是也能正常应用,但是对其使用和判断并不能信手拈来,所以下面这篇文章主要给大家介绍了关于js中this关键字的相关资料,文中通过实例代码介绍的非常详细,需要的朋友可以参考下
这篇文章主要为大家详细介绍了Vue分页组件的封装方法,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
jQuery中删除样式的方法是什么?对于删除样式我们可以利用removeAttr()方法和removeClass()方法,那么这两个方法具体是如何删除样式的呢?接下来我们一起来学习一下。
排他思想的算法就是排除掉其他的,本文主要介绍了JavaScript 排他思想的实现,以及介绍了两个示例,感兴趣的可以了解一下
本篇文章给大家带来了关于javascript的相关知识,其中主要整理了Number对象的相关问题,Number 对象是原始数值的包装对象,Number 创建方式 new Number(),下面一起来看一下,希望对大家有帮助。
成为群英会员,开启智能安全云计算之旅
立即注册关注或联系群英网络
7x24小时售前:400-678-4567
7x24小时售后:0668-2555666
24小时QQ客服
群英微信公众号
CNNIC域名投诉举报处理平台
服务电话:010-58813000
服务邮箱:service@cnnic.cn
投诉与建议:0668-2555555
Copyright © QY Network Company Ltd. All Rights Reserved. 2003-2020 群英 版权所有
增值电信经营许可证 : B1.B2-20140078 ICP核准(ICP备案)粤ICP备09006778号 域名注册商资质 粤 D3.1-20240008