Update MkTime.vue

This commit is contained in:
syuilo 2023-01-06 16:58:43 +09:00
parent 513cef50a2
commit 457670e730

View file

@ -36,23 +36,21 @@ const relative = $computed(() => {
i18n.ts._ago.future); i18n.ts._ago.future);
}); });
let tickId: number;
function tick() { function tick() {
now = new Date(); now = new Date();
const ago = (now.getTime() - _time.getTime()) / 1000/*ms*/; const ago = (now.getTime() - _time.getTime()) / 1000/*ms*/;
const next = ago < 60 ? 10000 : ago < 3600 ? 60000 : 180000; const next = ago < 60 ? 10000 : ago < 3600 ? 60000 : 180000;
tickId = window.setTimeout(() => { tickId = window.setTimeout(tick, next);
window.requestAnimationFrame(tick);
}, next);
} }
let tickId: number;
if (props.mode === 'relative' || props.mode === 'detail') { if (props.mode === 'relative' || props.mode === 'detail') {
tickId = window.requestAnimationFrame(tick); tick();
onUnmounted(() => { onUnmounted(() => {
window.cancelAnimationFrame(tickId); window.clearTimeout(tickId);
}); });
} }
</script> </script>