vue创建/清理 定时器

2 篇文章 0 订阅

countDown(down_time){

            /*var t1=this;

            var t=setInterval(function(){

                t1.time--;

                if(t1.time==0){

                    clearInterval(t);

                    /*触发自定义end事件,调用ending函数* /

                    //t1.$emit("end");

                    this.$toast.center('冲榜结束')

                }

            },1000)*/

            var t1=this;

            var end_time = down_time; //时间一定要new Data一下

            /*var now_time = Date.parse(new Date())/1000

            console.log('end_time:'+end_time)

            console.log('now_time:'+now_time)

            var time = end_time - now_time;

            console.log('time:'+time)

            var day = parseInt(time / 60 / 60 / 24);

            console.log('day:'+day)*/

            /*setInterval(function () {

                console.log('定时器执行中')

                var now_time = Date.parse(new Date())/1000

                var time = end_time - now_time;

                if(time > 0){

                    var day = parseInt(time / 60 / 60 / 24);

                    var hour = parseInt(time / 60 / 60 % 24);

                    var minute = parseInt(time / 60 % 60);

                    var seconds = parseInt(time % 60);

                    //t1.time = day + "天  " + hour + ":" + minute + ":" + seconds

                    t1.day = Public.timePreZero(day)

                    t1.hour = Public.timePreZero(hour)

                    t1.minute = Public.timePreZero(minute)

                    t1.seconds = Public.timePreZero(seconds)

                }else{

                    var day = 0

                    var hour = 0

                    var minute = 0

                    var seconds = 0

                }

                

            }, 1000);*/

clearIntervalTimer(){

            console.log('timer close')

            clearInterval(this.timer1)

            this.timer1 = null

        },

beforeDestroy(){

        //页面关闭时清除 定时器

        this.clearIntervalTimer()

    }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值