注意: 1.手机锁屏后定时器会停止, 直至开屏才继续,结果会错误, 所以需要在百度找解决方法( vux的倒计时不存在这个问题 )
例子
1(单个时间)
:
var
c
= Date
.parse(new Date()
)
;
var
e
= Date
.parse(new Date(_this.produce.fddDateE.replace(/-/g, "/")
))
;
if ((e > c)
&& (_this.produce.fdbStop == 0)
)
{//可用
_this.s
= e
- c
;
_this
.cutDown()
;
_this.timer
= setInterval(function ()
{
_this
.s
-=
1000
;
if (_this.s <= 0)
{
_this.s
=
0
;
_this
.cutDown()
;
clearInterval(_this.timer)
;
}
},
1000
)
;
}
cutDown()
{
var
demp
= parseInt(this.s/1000/60/60/24)
;
this
.cutDownArray[0]
= Math
.floor(demp/10)
; //0
this
.cutDownArray[1]
= demp
%
10
; //1天
demp
= parseInt(this.s/1000/60/60%24)
;
this
.cutDownArray[2]
= Math
.floor(demp/10)
; //1
this
.cutDownArray[3]
= demp
%
10
; //5时
demp
= parseInt(this.s/1000/60%60)
;
this
.cutDownArray[4]
= Math
.floor(demp/10)
; //2
this
.cutDownArray[5]
= demp
%
10
; //2分
demp
= parseInt(this.s/1000%60)
;
this
.cutDownArray[6]
= Math
.floor(demp/10)
; //1
this
.cutDownArray[7]
= demp
%
10
; //5秒
}
例子
2(循环数据都有各自的时间)
:
this.VoucherList
= res
.data
;
for(var i=0;i<res.data.length;i++)
{
if(res.data[i].mvouchermovieOverDate)
{
this.time1
= res
.data[i]
.mvouchermovieOverDate
var
c
= Date
.parse(new Date()
)
;
var
e
= Date
.parse(new Date(res.data[i].mvouchermovieOverDate.replace(/-/g, "/")
))
;
if ((e > c)
&& (res.data[i].fdiImportant == 1)
)
{//可用
this.s
= e
- c
;
this
.cutDown(res.data[i]['ID'])
;
var
_i=i
res
.data[i]
.time
= setInterval( ()
=>
{
//开始定时器
this
.s
-=
1000
;
this
.cutDown(res.data[_i]['ID'])
;
if (this.s <= 0)
{
this.s
=
0
;
clearInterval(res.data[_i]['ID'])
;
}
},
1000
)
;
}
}
}
cutDown(voucherID)
{
var
demp
= parseInt(this.s/1000/60/60/24)
;
this
.cutDownArray[0]
= Math
.floor(demp/10)
; //0
this
.cutDownArray[1]
= demp
%
10
; //1天
demp
= parseInt(this.s/1000/60/60%24)
;
this
.cutDownArray[2]
= Math
.floor(demp/10)
; //1
this
.cutDownArray[3]
= demp
%
10
; //5时
demp
= parseInt(this.s/1000/60%60)
;
this
.cutDownArray[4]
= Math
.floor(demp/10)
; //2
this
.cutDownArray[5]
= demp
%
10
; //2分
demp
= parseInt(this.s/1000%60)
;
this
.cutDownArray[6]
= Math
.floor(demp/10)
; //1
this
.cutDownArray[7]
= demp
%
10
; //5秒
for(var i=0;i<this.VoucherList.length;i++)
{
if(this.VoucherList[i]['ID'] == voucherID)
{
this
.VoucherList[i]
.intervalTime
=
""
this
.VoucherList[i]
.intervalTime
= this
.cutDownArray
}
}
},