Files
VRCX/src/components/Timer.vue
2025-11-27 02:34:15 +11:00

31 lines
681 B
Vue

<template>
<span>{{ text }}</span>
</template>
<script setup>
import { computed, onBeforeUnmount, onMounted, ref } from 'vue';
import { timeToText } from '../shared/utils';
const props = defineProps({
epoch: {
type: Number,
required: true
}
});
const now = ref(Date.now());
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>