From 457670e7306681c3d53fa25edf3235517579abe5 Mon Sep 17 00:00:00 2001 From: syuilo Date: Fri, 6 Jan 2023 16:58:43 +0900 Subject: [PATCH] Update MkTime.vue --- packages/frontend/src/components/global/MkTime.vue | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/packages/frontend/src/components/global/MkTime.vue b/packages/frontend/src/components/global/MkTime.vue index 704e6d0de..66c0bd513 100644 --- a/packages/frontend/src/components/global/MkTime.vue +++ b/packages/frontend/src/components/global/MkTime.vue @@ -36,23 +36,21 @@ const relative = $computed(() => { i18n.ts._ago.future); }); +let tickId: number; + function tick() { now = new Date(); const ago = (now.getTime() - _time.getTime()) / 1000/*ms*/; const next = ago < 60 ? 10000 : ago < 3600 ? 60000 : 180000; - tickId = window.setTimeout(() => { - window.requestAnimationFrame(tick); - }, next); + tickId = window.setTimeout(tick, next); } -let tickId: number; - if (props.mode === 'relative' || props.mode === 'detail') { - tickId = window.requestAnimationFrame(tick); + tick(); onUnmounted(() => { - window.cancelAnimationFrame(tickId); + window.clearTimeout(tickId); }); }