20 lines
466 B
TypeScript
20 lines
466 B
TypeScript
import { onMounted, onUnmounted, ref, shallowRef } from 'vue';
|
|
|
|
export function useNow(update_ms: number) {
|
|
const handle = shallowRef<number | undefined>(undefined);
|
|
const now = ref(Date.now());
|
|
|
|
onMounted(() => {
|
|
handle.value = setInterval(() => {
|
|
now.value = Date.now();
|
|
}, update_ms);
|
|
});
|
|
onUnmounted(() => {
|
|
if (handle.value) {
|
|
clearInterval(handle.value);
|
|
}
|
|
});
|
|
|
|
return now;
|
|
}
|