uniapp倒计时

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
    评论
uniapp中实现倒计时功能的方法可以参考以下步骤: 首先,你可以在data中定义倒计时需要显示的小时、分钟和秒数的变量,如countdownh、countdownm和countdowns,并初始化为相应的初始值。 然后,你可以创建一个计时器变量timer,并使用setInterval方法来重复执行倒计时函数。在倒计时函数中,你可以每隔一秒减少相应的小时、分钟和秒数。当倒计时结束时,清除计时器并将倒计时变量重置为0。 最后,你可以在需要显示倒计时的地方使用相应的变量来显示倒计时信息。比如在界面上显示倒计时的小时、分钟和秒数。 这样就可以实现uniapp中的倒计时功能了。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [uni-app实现简单的倒计时](https://blog.csdn.net/m0_46570767/article/details/119934272)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *2* *3* [uniapp实现倒计时功能](https://blog.csdn.net/EvaY_Yang/article/details/125312835)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值