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);
}
}
})
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。