微信小程序动态显示项目倒计时效果

  

本文实例为大家分享了微信小程序动态显示项目倒计时的具体代码,供大家参考,具体内容如下

  

1,一般我们说的显示秒杀都是指的单条数据,循环我没做。

  

效果:   

微信小程序动态显示项目倒计时效果

  

2, wxml代码:

        & lt; p>   & lt;块wx:如果=" {{total_micro_second<=0}}”在剩余时间:已经截止& lt;/block>   & lt;块wx:如果="{{钟!=币丫刂埂瘆}”在剩余时间:{{时钟}}& lt;/block>   & lt;/p>   之前      

3 . js文件代码:

        函数倒计时(){   var EndTime=that.data。end_time | | [];   .getTime var NowTime=new日期()();   var total_micro_second=EndTime - NowTime | | [];   控制台。日志(“剩余时间:“+ total_micro_second);//渲染倒计时时钟   that.setData ({   钟:dateformat (total_micro_second)   });   如果(total_micro_second & lt;=0) {   that.setData ({   钟:“已经截止”   });//返回;   }   setTimeout(函数(){   total_micro_second -=1000;   倒计时(,);   }   ,1000)   }//时间格式化输出,如11:03 25:19每1 s都会调用一次   函数dateformat (micro_second) {//总秒数   var=数学。地板(micro_second/1000);//天数   var天=Math.floor(第二/3600/24);//小时   var hr=Math.floor(第二次/24)3600%;//分钟   var min=Math.floor(60秒/60%);//秒   var秒=Math.floor(第二% 60);   返回日”+“天”+人力资源+小时“+分钟+”分钟”+秒+“秒”;   }      页面({/* *   *页面的初始数据   */数据:{   id:”,   结果:[],   end_time:”,   钟:“   },/* *   *生命周期函数——监听页面加载   */onLoad:功能(选项){   var=这个;   wx.request ({   url: https://m。* * * * * *.com/index.php/Home/Xiaoxxf/activity_detail& # 63; a_id=' + options.id,//不含富文本html   数据:{},   方法:‘得到’,//选择,,,,,删除、跟踪,连接   标题:{   “内容类型”:“application/json”   },   成功:函数(res) {   that.setData ({   常见:res.data,//一维数组,全部数据   end_time: res.data。end_time//项目截止时间,时间戳,单位毫秒   })   console.log (that.data.common);   控制台。日志(“结束时间:“+ that.data.end_time);   },   失败:函数(res) {},   完成:函数(res) {},   }),//调用上面定义的递归函数,一秒一刷新时间   倒计时(,);   },   之前      

为大家推荐现在关注度比较高的微信小程序教程一篇:《微信小程序开发教程》小编为大家精心整理的,希望喜欢。

  

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。

微信小程序动态显示项目倒计时效果