vue中封装一个倒计时
<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;"> days</span>
</div>
</div>
<div class="row resetStyle">
<div class="col col-xs-4 resetStyle height58">
<span class="bigFont">{{time.h}}</span> hrs
</div>
<div class="col col-xs-4 resetStyle height58">
<span class="bigFont">{{time.m}}</span> mins
</div>
<div class="col col-xs-4 resetStyle height58">
<span class="bigFont">{{time.s}}</span> 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中封装一个倒计时的更多相关文章
- vue中封装一个全局的弹窗js
/** * Created by yx on 2017/12/21. */ export default { /** * 带按钮的弹框 * <!--自定义提示标题,内容,单个按钮事件--> ...
- IOS中封装一个View的思路
一.封装一个View的思路 1.将View内部的业务逻辑(显示内容)封装到View中 2.一般情况下,View的位置应该由父控件来决定,也就是位置不应该固定死在View内部 3.至于View的宽高,根 ...
- 项目开发中封装一个BarButtonItem类别-很实用
Encapsulates a TabBarItem--封装一个BarButtonItem类 在我们程序的导航栏的左边或右边一般都会有这样的BarButtonItem,用来界面之间的跳转 如果我们有很多 ...
- vue中methods一个方法调用另外一个方法
转自http://blog.csdn.net/zhangjing1019/article/details/77942923 vue在同一个组件内: methods中的一个方法调用methods中的另外 ...
- 使用vue.js封装一个包含图片的跑马灯组件
初衷: 学习完Vuejs后,来准备练习仿写一下老东家的门户页面,主要是为了熟悉一下常用插件的使用,比如video.js,wow.js,swiper等等:而其中涉及到一个包含图片跑马灯组件,大概长这样( ...
- 使用better-scroll在vue中封装自己的Scroll组件
1. better-scroll 原理 用一张图感受: 绿色部分为 wrapper,也就是父容器,它会有固定的高度.黄色部分为 content,它是父容器的第一个子元素,它的高度会随着内容的大小而撑高 ...
- 在Lua中封装一个调试日志(附lua时间格式)
--自己封装一个Debug调试日志 Debug={} Info={} local function writeMsgToFile(filepath,msg) end function Debug.Lo ...
- 在vue中写一个跟着鼠标跑的div,div里面动态显示数据
1.div应该放在body里面,这是我放在body中的一个div里面的div <!-- 信息查看层 --> <div class="floatDiv" :styl ...
- js中封装一个自己的简单数学对象
封装一个数学对象求最大值最小值 <script> var myMath={ PI:3.1415926, max:function(){ var max=arguments[0];//注意a ...
随机推荐
- Luogu5400 CTS2019随机立方体(容斥原理)
考虑容斥,计算至少有k个极大数的概率.不妨设这k个数对应的格子依次为(k,k,k)……(1,1,1).那么某一维坐标<=k的格子会对这些格子是否会成为极大数产生影响.先将这样的所有格子和一个数集 ...
- DO、VO、DTO 区别
DTO:数据传输对象,主要用于外部接口参数传递封装,接口与接口进行传递使用. VO:视图对象,主要用于给前端返回页面参数使用. DO:数据对象,主要用于数据库层传递. DTO转DO:接口接收参数将参数 ...
- springboot_2
1. 配置文件简介 spring boot使用一个全局配置文件:application.properties或者application.yml,放置在src/main/resources目录下或者类路 ...
- VS2015编译Teamtalk的Windows客户端(转)
原文链接:https://blog.csdn.net/qtstar/article/details/54732581 一.(首先要把teamtalk整个项目download下来或git一个副本下来)打 ...
- 由于找不到MSVCP140.dll,无法继续执行代码。重新安装程序可能会解决此问题。
msvcp140.dll文件下载,解决找不到msvcp140.dll的问题: 如果您的系统是64位的请将32位的dll文件复制到C:\Windows\System32目录 如果您的系统是64位的请将3 ...
- SAP Marketing Cloud功能简述(二) : Target Group
这个系列的第一篇文章 SAP Marketing Cloud功能简述(一) : Contacts和Profiles,我向大家介绍了SAP Marketing Cloud里的Contacts和Profi ...
- 父类调用子类的常量 lumen查询数据库方式
我要在一个基类里面实例化所有的model 要根据集成的对象定义的model实例化 BaseRepository.php <?php namespace App\Repository; class ...
- 【Zookeeper】本地ZK的搭建
很久没有写了..最近看书的笔记都记在有道云上面..框架的使用觉得还是有必要写一下 1.下载 官网:https://www.apache.org/dyn/closer.cgi 清华镜像:https:// ...
- python txt文件读写(追加、覆盖)
(1)在lucky.txt中新增内容(覆盖:每次运行都会重新写入内容) f = "lucky.txt" a =8 with open(f,"w") as fil ...
- JAVA中为什么要使用接口,继承接口不是还要重写方法吗?为什么不直接写那些方法呢?:::接口的最主要的作用是达到统一访问
接口的最主要的作用是达到统一访问 那么什么叫统一访问呢 举个例子 你这样想,我做一个USB接口,有个读的抽象方法 那叫read()吧,然后mp3类实现,U盘类实现,移动硬盘类实现,这样我用的时候用US ...