vue2.0倒计时,vue2.0 js 倒计时,vue倒计时
Meta charset="UTF-8">方法体 methods: { num: function (n) { return n < 10 ? '0' + n : '' + n }, timeToData:function ( maxtime ) { second = Math.floor( maxtime % 60); //计算秒 minite = Math.floor((maxtime / 60) % 60); //计算分 hour = Math.floor((maxtime / 3600) % 24 ); //计算小时 day = Math.floor((maxtime / 3600) / 24);//计算天 return day+'天'+this.num(hour)+'时'+this.num(minite)+'分'+this.num(second)+'秒'; }, getTime:function () { var that = this; setInterval(function () { that.list.forEach(function (value) { var shijian = that.timeToData(value.time); if( typeof value.jishi == 'undefined' ) { that.$set(value,'jishi',shijian); }else { value.jishi = shijian; } if( value.time ) { -- value.time; }else { value.time = 0; } }) }, 1000); } }, //页面打开渲染之前就调用 created: function () { var that = this; that.getTime(); } });