<template>
<div class="countDownBox">
<div class="row resetStyle">
<div class="col col-xs-6 resetStyle height58">
<p style="line-height:29px;text-align:left;text-indent:20px;">Conference</p>
<p style="line-height:29px;text-align:left;text-indent:20px;">starts in</p>
</div>
<div class="col col-xs-6 resetStyle height58">
<span class="bigFont" style="font-size:50px;font-weight:bold;color:#ff8e44;">{{time.D}}</span>
<span style="color:#ff8e44;">&nbsp;days</span>
</div>
</div>
<div class="row resetStyle">
<div class="col col-xs-4 resetStyle height58">
<span class="bigFont">{{time.h}}</span>&nbsp;hrs
</div>
<div class="col col-xs-4 resetStyle height58">
<span class="bigFont">{{time.m}}</span>&nbsp;mins
</div>
<div class="col col-xs-4 resetStyle height58">
<span class="bigFont">{{time.s}}</span>&nbsp;secs
</div>
</div>
</div>
</template> <script>
export default {
data(){
return{
isEnd:false,//倒计时是否结束
endTime:'2022-09-21 00:00:00',//应为接口获取到的结束时间
time:{D:"0",h:"0",m:"0",s:"0"},//时间
}
},
created(){
var self=this;
self.setEndTime();
},
mounted(){ },
methods:{
setEndTime(){
var that = this;
       that.endTime=that.endTime.replace(/\-/g, "/"); //加这一行代码是为了兼容safari浏览器 因为safari浏览器根据字符串转换日期的时候支持"2016/05/31 08:00"这种格式 不支持"2016-05-31 08:00"这种格式
var interval = setInterval(function timestampToTime(){
var date = (new Date(that.endTime)) - (new Date()); //计算剩余的毫秒数
if(date <= 0){
that.isEnd = true;
clearInterval(interval)
}else{
that.time.D = parseInt(date / 1000 / 60 / 60 / 24 , 10);
that.time.h = parseInt(date / 1000 / 60 / 60 % 24 , 10);
if(that.time.h < 10){
that.time.h = "0" + that.time.h
}
that.time.m = parseInt(date / 1000 / 60 % 60, 10);//计算剩余的分钟
if(that.time.m < 10){
that.time.m = "0" + that.time.m
}
that.time.s = parseInt(date / 1000 % 60, 10);//计算剩余的秒数
if(that.time.s < 10){
that.time.s = "0" + that.time.s
}
that.time=Object.assign({},that.time)
return that.time;
}
},1000);
},
}
}
</script> <style scoped>
.countDownBox{
width:290px;
height:116px;
float: right;
margin-top:74px;
}
@media screen and (max-width: 990px) {
.countDownBox{
display: none;
}
}
@media screen and (min-width: 900px) { }
.resetStyle{
margin:0;
padding:0;
}
.height58{
height:58px;
line-height:58px;
text-align: center;
color:#34704c;
font-size:16px;
font-family: 'Courier New', Courier, monospace;
font-weight:600;
}
.bigFont{
font-size:40px;
}
</style>

vue中封装一个倒计时的更多相关文章

  1. vue中封装一个全局的弹窗js

    /** * Created by yx on 2017/12/21. */ export default { /** * 带按钮的弹框 * <!--自定义提示标题,内容,单个按钮事件--> ...

  2. IOS中封装一个View的思路

    一.封装一个View的思路 1.将View内部的业务逻辑(显示内容)封装到View中 2.一般情况下,View的位置应该由父控件来决定,也就是位置不应该固定死在View内部 3.至于View的宽高,根 ...

  3. 项目开发中封装一个BarButtonItem类别-很实用

    Encapsulates a TabBarItem--封装一个BarButtonItem类 在我们程序的导航栏的左边或右边一般都会有这样的BarButtonItem,用来界面之间的跳转 如果我们有很多 ...

  4. vue中methods一个方法调用另外一个方法

    转自http://blog.csdn.net/zhangjing1019/article/details/77942923 vue在同一个组件内: methods中的一个方法调用methods中的另外 ...

  5. 使用vue.js封装一个包含图片的跑马灯组件

    初衷: 学习完Vuejs后,来准备练习仿写一下老东家的门户页面,主要是为了熟悉一下常用插件的使用,比如video.js,wow.js,swiper等等:而其中涉及到一个包含图片跑马灯组件,大概长这样( ...

  6. 使用better-scroll在vue中封装自己的Scroll组件

    1. better-scroll 原理 用一张图感受: 绿色部分为 wrapper,也就是父容器,它会有固定的高度.黄色部分为 content,它是父容器的第一个子元素,它的高度会随着内容的大小而撑高 ...

  7. 在Lua中封装一个调试日志(附lua时间格式)

    --自己封装一个Debug调试日志 Debug={} Info={} local function writeMsgToFile(filepath,msg) end function Debug.Lo ...

  8. 在vue中写一个跟着鼠标跑的div,div里面动态显示数据

    1.div应该放在body里面,这是我放在body中的一个div里面的div <!-- 信息查看层 --> <div class="floatDiv" :styl ...

  9. js中封装一个自己的简单数学对象

    封装一个数学对象求最大值最小值 <script> var myMath={ PI:3.1415926, max:function(){ var max=arguments[0];//注意a ...

随机推荐

  1. C# 字符串按设置的格试在前面或后面增加空格或其它字符

    public string lengadd(string stringa, string stringb, int count, int mode) //以stringa的长度,未到count的长度则 ...

  2. 转 C# GDI+ 实现橡皮筋技术

    http://www.cnblogs.com/arxive/p/6080085.html 应该有很多人都在寻找这方面的资料,看看下面我做的,或许对你会有所帮助,但愿如此. 为了实现橡皮筋技术,我用了两 ...

  3. interface Part2(定义接口)

    一. 在 C# 语言中,类之间的继承关系仅支持单重继承,而接口是为了实现多重继承关系设计的. 二. 一个类能同时实现多个接口,还能在实现接口的同时再继承其他类,并且接口之间也可以继承. 三. 无论是表 ...

  4. MySQL中You can't specify target table '表名'('sn_app_label') for update in FROM clause错误解决办法

    在有些时候有级联关系的数据放在了同一张表中,在写sql语句的时候可能会遇到这样的场景:我要插入两条数据,第一条是父节点,第二条是子节点,关联关系是父节点的自增长id:在写这样的sql语句时有可能就会出 ...

  5. 数据结构之链表(LinkedList)(三)

    数据结构之链表(LinkedList)(二) 环形链表 顾名思义 环形列表是一个首尾相连的环形链表 示意图 循环链表的特点是无须增加存储量,仅对表的链接方式稍作改变,即可使得表处理更加方便灵活. 看一 ...

  6. 四、eureka服务端同步注册操作

    所有文章 https://www.cnblogs.com/lay2017/p/11908715.html 正文 在eureka服务端注册服务一文中,我们提到register方法做了两件事 1)注册服务 ...

  7. 1+x证书学习日志——css常用属性

     ## css常用属性:             1:文本属性:                 文本大小:  font-size:18px;                 文本颜色    colo ...

  8. CSS选取第一个、最后一个、偶数、奇数、第n个标签元素

    1.first-child first-child表示选择列表中的第一个标签.例如:li:first-child{background:#fff} 2.last-child last-child表示选 ...

  9. Android笔记(三十二) Android中线程之间的通信(四)主线程给子线程发送消息

    之前的例子都是我们在子线程(WorkerThread)当中处理并发送消息,然后在主线程(UI线程)中获取消息并修改UI,那么可以不可以在由主线程发送消息,子线程接收呢?我们按照之前的思路写一下代码: ...

  10. nginx的应用【虚拟主机】

    Nginx主要应用: 静态web服务器 负载均衡 静态代理虚拟主机 虚拟主机 :虚拟主机,就是把一台物理服务器划分成多个“虚拟”的服务器,这样我们的一台物理服务器就可以当做多个服务器来使用,从而可以配 ...