setIntervalを再設定する
This commit is contained in:
parent
0dbb9cf400
commit
c8f14d252c
|
@ -50,19 +50,25 @@ let tickId: number;
|
||||||
|
|
||||||
function tick() {
|
function tick() {
|
||||||
const _now = (new Date()).getTime();
|
const _now = (new Date()).getTime();
|
||||||
const ago = (_now - _time) / 1000/*ms*/;
|
const agoPrev = (now - _time) / 1000/*ms*/; // 現状のinterval
|
||||||
|
|
||||||
|
now = _now;
|
||||||
|
|
||||||
|
const ago = (now - _time) / 1000/*ms*/; // 次のinterval
|
||||||
|
const prev = agoPrev < 60 ? 10000 : agoPrev < 3600 ? 60000 : 180000;
|
||||||
const next = ago < 60 ? 10000 : ago < 3600 ? 60000 : 180000;
|
const next = ago < 60 ? 10000 : ago < 3600 ? 60000 : 180000;
|
||||||
|
|
||||||
if (_now - now > next) {
|
if (!tickId) {
|
||||||
// nowが代入されるとrelativeが再計算される
|
tickId = window.setInterval(tick, next);
|
||||||
// relativeが再計算されると色々重たいので、nowの更新は必要以上に行わない
|
} else if (prev < next) {
|
||||||
now = _now;
|
window.clearInterval(tickId);
|
||||||
|
tickId = window.setInterval(tick, next);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!invalid && props.origin === null && (props.mode === 'relative' || props.mode === 'detail')) {
|
if (!invalid && props.origin === null && (props.mode === 'relative' || props.mode === 'detail')) {
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
tickId = window.setInterval(tick, 10000);
|
tick();
|
||||||
});
|
});
|
||||||
onUnmounted(() => {
|
onUnmounted(() => {
|
||||||
if (tickId) window.clearInterval(tickId);
|
if (tickId) window.clearInterval(tickId);
|
||||||
|
|
Loading…
Reference in New Issue