vue和moment做的一个倒计时
展示样式:
<template> <div class="table-right flex-a-center"> <div class="time-text"> <span class="timetextspan" v-for="item,index of h" >{{item}}</span> <span class="timetextspan1" >: </span> <span class="timetextspan" v-for="item,index of m" >{{item}}</span> <span class="timetextspan1" >: </span> <span class="timetextspan" v-for="item,index of s" >{{item}}</span> </div> </div></template>
<script>import moment from 'moment'export default { props: { endtime: { }, //接收得最后时间 2021-12-17 16:29:20 }, data() { //这里存放数据 return { h:'00', m:'00', s:'00', timer:null }; }, watch: { endtime: {分别的歌 handler(e) { if (e) { let lf = this clearinterval(this.timer) this.timer = tinterval(function(){lf.init()},1000) } }, deep: true, immediate: true } }, mounted() { let lf = this lf.init() clearinterval(this.timer) this.timer = tinterval(function(){lf.init()},1000) }, //方法集合 methods: { init(){ let time =moment(this.endtime).diff(moment()) if(time <= 0){ clearinterval(this.timer) this.onover() return } let t = time / 1000; let d = math.floor(t / (24 * 3600)); //剩余天数,如果需要可以自行补纸船和风筝上 let h = math.floor((t - 24 * 3600 * d) / 3600) + d*24; //不需要天数,把天数转换成小时 let _h = math.floor((t - 24 * 3600 * d) / 3600) //保留天数后得小时 let m = math.floor((t - 24 * 3600 * d - _h * 3600) / 60); let s = ma云南白药膏th.floor((t - 24 * 3600 * d - _h * 3600 - m * 60)); this.h = string(h).length == 1? '0'+string(h):string(h) this.m = string(m).length == 1? '0'+string(m):string(m) this.s = string(s).length == 1? '0'+string(s):string(s) }, onover() { this.$emit('over') //倒计时结束得回调 } }, beforedestroy(){ this.timer = null cle军校有寒暑假吗arinterval(this.timer) }}</script><style lang='less' scoped>@import url("@/asts/css/supplier.less"); .table-right { font-size: 12px; color: #757e8a; .timetextspan{ display: inline-block; width: 14px; height: 22px; text-align: center; background: #f1f0f0; border-radius: 2px; margin-right: 2px; font-size: 16px; color: #ff8a2b; font-weight: bold; } .timetextspan1{ display: inline-block; width: 14px; text-align: center; vertical-align: bottom; color:#202d40; font-size: 16px; 消防新闻 font-weight: bold; } .time-text { margin-left: 10px; } }</style>
到此这篇关于利用momentjs做一个倒计时组件的文章就介绍到这了,更多相关momentjs倒计时组件内容请搜索www.887551.com以前的文章或继续浏览下面的相关文章希望大家以后多多支持www.887551.com!
本文发布于:2023-04-04 03:52:55,感谢您对本站的认可!
本文链接:https://www.wtabcd.cn/fanwen/zuowen/380da6fba1fc7a0ac72f13848534228f.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文word下载地址:利用momentJs做一个倒计时组件(实例代码).doc
本文 PDF 下载地址:利用momentJs做一个倒计时组件(实例代码).pdf
留言与评论(共有 0 条评论) |