use vueuse

This commit is contained in:
pa
2026-03-15 21:17:02 +09:00
parent 8624ac20fa
commit 9e0116fce7
9 changed files with 48 additions and 199 deletions

View File

@@ -2,7 +2,8 @@
<span>{{ text }}</span>
</template>
<script setup>
import { computed, onBeforeUnmount, onMounted, ref } from 'vue';
import { useNow } from '@vueuse/core';
import { computed } from 'vue';
import { timeToText } from '../shared/utils';
@@ -13,18 +14,8 @@
}
});
const now = ref(Date.now());
const now = useNow({ interval: 15000 });
const text = computed(() => {
return props.epoch ? timeToText(now.value - props.epoch) : '-';
});
let timerId = null;
onMounted(() => {
timerId = setInterval(() => {
now.value = Date.now();
}, 15000);
});
onBeforeUnmount(() => {
clearInterval(timerId);
});
</script>