uniapp倒计时

本文介绍了uni-app中uni-countdown组件的使用方法,通过示例代码展示了如何设置倒计时的天数、小时、分钟和秒数,并且在数据变化时更新倒计时。同时,还提供了一个名为'daojishi'的方法,用于计算剩余时间并更新组件状态。此外,还涉及到与后台API的交互,获取并处理数据以实现动态倒计时。
摘要由CSDN通过智能技术生成

uni-countdown 倒计时 - DCloud 插件市场  倒计时

<uni-count-down 
    :day="currentTime.d" 
    :hour="currentTime.h" 
    :minute="currentTime.i" 
    :second="currentTime.s" 
    color="#FA5B14"
    splitorColor="#FF4644"
/>
data(){
    return{
        Countdown: '',
		currentTime: '',
		noStartTime: '',
		timestamp: '',
		xxx: '',
    }
},

countDown(seconds) {
    let [day, hour, minute, second] = [0, 0, 0, 0]
	if (seconds > 0) {
		day = Math.floor(seconds / (60 * 60 * 24))
		hour = Math.floor(seconds / (60 * 60)) - (day * 24)
		minute = Math.floor(seconds / 60) - (day * 24 * 60) - (hour * 60)
		second = Math.floor(seconds) - (day * 24 * 60 * 60) - (hour * 60 * 60) - (minute * 60)
	}
	if (day < 10) {
		day = '0' + day
	}
	if (hour < 10) {
		hour = '0' + hour
	}
	if (minute < 10) {
		minute = '0' + minute
	}
	if (second < 10) {
		second = '0' + second
	}
	return {
		d: day,
		h: hour,
		i: minute,
		s: second
	};
},


daojishi(end_time, start_time, timestamp) {
    let res = this.$util.countDown(end_time - start_time);
	if (res.d <= 0 && res.h <= 0 && res.i <= 0 && res.s <= 0) {
	    return
	}
	this.currentTime = this.countDown(end_time - timestamp);
	this.noStartTime = this.countDown(start_time - timestamp);
	this.Countdown = res.d + "天" + res.h + "小时" + res.i + "分钟" + res.s + "秒";
},

this.$api.sendRequest({
    url: 'url ',
    data: {},
	success: res => {
	    if (res.code >= 0) {
			this.xxxx = res.data;
			this.daojishi(res.data.end_time, res.data.start_time, res.timestamp);
		}
    }
})

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值