countdown(timestamp) {
let self = this;
let timer = setInterval(function () {
let nowTime = new Date();
let endTime = new Date(timestamp * 1000);
let t = endTime.getTime() - nowTime.getTime();
if (t > 0) {
self.setData({
showEnd: false
})
let day = Math.floor(t / 86400000);
let hour = Math.floor((t / 3600000) % 24);
let min = Math.floor((t / 60000) % 60);
let sec = Math.floor((t / 1000) % 60);
hour = hour < 10 ? '0' + hour : hour;
min = min < 10 ? '0' + min : min;
sec = sec < 10 ? '0' + sec : sec;
if (day > 0) {
self.setData({
day: day,
hour: hour,
min: min,
sec: sec,
});
}
if (day <= 0 && hour > 0) {
self.setData({
day: 0,
hour: hour,
min: min,
sec: sec,
});
}
if (day <= 0 && hour <= 0) {
self.setData({
hour: '00',
min: min,
sec: sec,
});
}
} else {
self.setData({
showEnd: true
})
clearInterval(timer);
}
}, 1000);
},
},
请问这个问题最后是怎么解决的呢
仔细检查一下代码,如果无法解决可以贴更详细的代码我再看看