局部过滤器

时间、***号

<div id="wrapper" class="wrapper" style="display: none;">
距离活动结束还剩:<p v-html="times"></p>
</div>
<script src="vue.min.js"></script>
<script src="axios.min.js"></script>
<script src="qs.min.js"></script>
var mainVM = new Vue({
el: '#wrapper',
data: {
initActiveMsgObj:{}, // 接收接口返回的数据
timer: null, // 计时器
times: '<span>0</span>天<span>00</span>时<span>0</span>分', // 倒计时到分钟,比真正的秒还差60秒,需要赋值的时候加进去,如果是到秒,就不需要了
countDown: 0
},
filters: {
formatNumber(value){ // 格式化金额
var nStr = value;
if(!nStr){return nStr;}
nStr += '';
x = nStr.split('.');
x1 = x[0];
if(!x[1]){
x[1] = '00';
}
x2 = x.length > 1 ? '.' + x[1] : '';
var rgx = /(\d+)(\d{3})/;
while (rgx.test(x1)) {
x1 = x1.replace(rgx, '$1' + ',' + '$2');
}
return x1 + x2;
},
formatDate(timestamp) {
if (!timestamp) return;
var date = new Date(timestamp * 1000);
var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1);
var D = (date.getDate() < 10 ? '0' + date.getDate() : date.getDate());
return M + "." + D;
},
formatDateChina(timestamp) {
if (!timestamp) return;
var date = new Date(timestamp * 1000);
var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1);
var D = (date.getDate() < 10 ? '0' + date.getDate() : date.getDate());
return M + "月" + D + "日";
},
},
mounted() {
document.getElementById('wrapper').style.display = 'block';
},
created() {
this.getDetail();
},
methods: {
getDetail(){ // 初始化数据
axios({
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
},
method: 'post',
dataType: "json",
data: Qs.stringify({
tid: this.GetQueryString('tid'), // 从url上获取id
}),
url: url,
}).then(function (res) {
if(res.data && res.data.result){
res = res.data
if(res.status == 200){
mainVM.initActiveMsgObj = res.result;
mainVM.countDown = Number(res.result.end_time) + 60; // 这里如果是时间到分钟,需要增加一个60s,这样防止,到00还需要等一分钟才结束活动,如果显示到秒就不需要了次变量了。
mainVM.timeDown();
}else{
}
}
}).catch(function(error){ })
},
GetQueryString(name) {
var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
var r = window.location.search.substr(1).match(reg);
if (r != null) return unescape(r[2]);
return null;
},
timeDown() { // 倒计时
clearInterval(this.timer);
var starttime = this.initActiveMsgObj.start_time;
var nowDate = Math.round(new Date() / 1000); // 当前时间
//var endtime = Number(this.initActiveMsgObj.end_time);
var endtime = this.countDown;
// endtime = Math.round(new Date('2019/7/10 14:56:00') / 1000); + 60;
if(endtime < nowDate){return}
var totalSeconds = parseInt((endtime - nowDate)); // 相差的总秒数
//天数
var days = Math.floor(totalSeconds / (60 * 60 * 24));
//取模(余数)
var modulo = totalSeconds % (60 * 60 * 24);
//小时数
var hours = Math.floor(modulo / (60 * 60));
hours = hours < 10 ? ('0' + hours) : hours;
modulo = modulo % (60 * 60);
//分钟
var minutes = Math.floor(modulo / 60);
minutes = minutes < 10 ? '0' + minutes : minutes;
// console.log(minutes)
//秒
// var seconds = modulo % 60;
// console.log(seconds);
//输出到页面
this.times = '<span>'+ days +'</span>天<span>'+ hours +'</span>时<span>'+ minutes +'</span>分';
// console.log(days + "天" + hours + "时" + minutes + "分");
//if(totalSeconds <= 0){
if(totalSeconds <= 60){
clearInterval(this.timer);
window.location.reload()
}else{
this.timer = setInterval(this.timeDown, 1000);
}
},
}
})

Vue -- filters 过滤器、倒计时效果的更多相关文章

  1. vue filters过滤器

    vue filters过滤器 vue.js允许我们自定义过滤器,可被使用于一些常见的文本格式化,过滤器可以用在两个地方,双花括号插值和 v-bind表达式.最常见的就是双花括号插值. 比如如下代码:{ ...

  2. vue filters过滤器的使用

    说的很详细 https://www.w3cplus.com/vue/how-to-create-filters-in-vuejs.html

  3. 六、vue基础--过滤器定义

    七.过滤器定义 1.使用:{{username|strip}}.<a :href="url|strip">百度</a> 2.定义:都是定义一个函数,这个函数 ...

  4. Vue学习之--------Vue中过滤器(filters)的使用(代码实现)(2022/7/18)

    1.过滤器 1.1 概念 过滤器: 定义:对要显示的数据进行特定格式化后再显示(适用于一些简单逻辑的处理). 语法: 1.注册过滤器:Vue.filter(name,callback) 或 new V ...

  5. Vue.js Cookbook: 添加实例属性; 👍 axios(4万➕✨)访问API; filters过滤器;

    add instance properties //加上$,防止和已经定义的data,method, computed的名字重复,导致被覆写.//可以自定义添加其他符号. Vue.prototype. ...

  6. vue自定义过滤器的创建和使用

    1.简单介绍   过滤器的作用:实现数据的筛选.过滤.格式化.   过滤器的本质是一个有参数,有返回值的方法.   过滤器可以用在两个地方:双花括号插值和v-bind表达式(后者从2.1.0+开始支持 ...

  7. Vue自定义过滤器

    gitHub地址: https://github.com/lily1010/vue_learn/tree/master/lesson05 一 自定义过滤器(注册在Vue全局) 注意事项: (1)全局方 ...

  8. Asp.Net MVC 3【Filters(过滤器)】

    这里分享MVC里的Filters(过滤器),什么是MVC里的过滤器,他的作用是什么? 过滤器的请求处理管道中注入额外的逻辑.他们提供了一个简单而优雅的方式来实现横切关注点.这个术语是指所有对应用程序的 ...

  9. vue filter过滤器简单应用

    vue中过滤器,用于一些常见的文本格式化,用 | 来操作. 过滤器可以用在两个地方: 1.在{{}}双花括号中插入值 2.v-bind表达式中使用 <!-- 在双花括号中 --> {{ m ...

随机推荐

  1. ztree通过id获取节点对象

    var treeObj = $.fn.zTree.getZTreeObj("treeId"); var node = treeObj.getNodeByParam("id ...

  2. 对比JPA 和Hibernate 和 Mybatis的区别

    1.JPA.Hibernate.Mybatis简单了解 1.JPA:本身是一种ORM规范,不是ORM框架.由各大ORM框架提供实现. 2.Hibernate:目前最流行的ORM框架,设计灵巧,文档丰富 ...

  3. 15-16 ICPC europe J Saint John Festival (graham扫描法+旋转卡壳)

    题意:给n个大点,m个小点$(n<=1e5,m<=5e5),问有多少个小点,存在3个大点,使小点在三个大点组成的三角形内. 解题思路: 首先,易证,若该小点在某三大点行成的三角形内,则该小 ...

  4. 【Leetcode】746. Min Cost Climbing Stairs

    题目地址: https://leetcode.com/problems/min-cost-climbing-stairs/description/ 解题思路: 官方给出的做法是倒着来,其实正着来也可以 ...

  5. Go实战--golang中使用redis(redigo和go-redis/redis)

    开源库redigo的使用 github地址: https://github.com/garyburd/redigo 文档地址: http://godoc.org/github.com/garyburd ...

  6. 剪贴板神器:Ditto

    ditto – 善用佳软 免费开源的 Windows 管理剪贴板,让你处理文字更高效:Ditto - 少数派

  7. ubuntu 安装 Java 开发环境

    可以使用命令 -jre-headless 或者使用:   本文链接:https://blog.csdn.net/sangewuxie/article/details/80958611 本人的ubunt ...

  8. 以前我对你不够好,我也很难受——CSS篇

    1)文字下划线.删除线.定划线 Text-decoration:underline /*下划线*/ Text-decoration:overline     /*顶划线*/ Text-decorati ...

  9. Spring Cloud Alibaba学习笔记(11) - RocketMQ事务消息

    在Spring中,我们要实现事务,一般通过@Transactional注解实现.这在引入RocketMQ之前没有问题,但是在引入了RocketMQ之后,如果消息发送之后的业务逻辑处理发生了异常的话,这 ...

  10. 【SQL Server DBA】维护语句:删除并创建外键约束、获取建表语句

    原文:[SQL Server DBA]维护语句:删除并创建外键约束.获取建表语句 1.删除外键约束,建立外键约束 先建立3个表: /* drop table tb drop table tb_b dr ...