uniapp倒计时

uniapp实现根据传递的时间展示倒计时

需求说明:听书倒计时,设置完时间展示倒计时

countDownTime(showTime){
    
     //showTime为传递的时间 默认在转化成分钟
	var that = this;
	that.times = showTime * 60

	that.timer = setInterval(function() {
    
    
		that.times--;
		if(that.times == 0){
    
    
	        //时间到了清除计时器
			clearInterval(that.timer);
		}
		var minutes = Math.floor(that.times / 60);
		var seconds = Math.floor(that.times % 60);
		that.timeMsg = `${
     
     minutes}:${
     
     seconds}`
	}, 1000)
}, //data定义的timeMsg为展示的倒计时时间

展示形式:
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/weixin_43877575/article/details/131291120