前端倒计时工具

简述:应用环境平常为考试倒计时,获取验证码倒计时

运行环境为vue、小程序

/** 初始数据 */
data(){
    return{
        agreeCountDown: '00:02:00', //展示
        agreeCountTime: 2 * 60, //运算
        agreeShow: true,
    }
}

/** 倒计时开始事件 */
getCode(){
    let that = this;
 let maxtime = that.agreeCountTime;
 let timer = setInterval(function () {
        if (maxtime <= 0) {
            clearInterval(timer);
            that.agreeShow = false;
            return; 
        }
        maxtime--;
        let minutes = ('0' + Math.floor(maxtime / 60)).substr(-2);
        let seconds = ('0' + Math.floor(maxtime % 60)).substr(-2);
        let msg = '00:' + minutes + ':' + seconds;
        that.agreeCountDown = msg
        console.log(that.agreeCountDown)
    }, 1000);
},

你可能感兴趣的:(前端倒计时工具)