rename: client -> frontend
This commit is contained in:
parent
db6fff6f26
commit
9384f5399d
592 changed files with 111 additions and 111 deletions
24
packages/frontend/src/scripts/use-interval.ts
Normal file
24
packages/frontend/src/scripts/use-interval.ts
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
import { onMounted, onUnmounted } from 'vue';
|
||||
|
||||
export function useInterval(fn: () => void, interval: number, options: {
|
||||
immediate: boolean;
|
||||
afterMounted: boolean;
|
||||
}): void {
|
||||
if (Number.isNaN(interval)) return;
|
||||
|
||||
let intervalId: number | null = null;
|
||||
|
||||
if (options.afterMounted) {
|
||||
onMounted(() => {
|
||||
if (options.immediate) fn();
|
||||
intervalId = window.setInterval(fn, interval);
|
||||
});
|
||||
} else {
|
||||
if (options.immediate) fn();
|
||||
intervalId = window.setInterval(fn, interval);
|
||||
}
|
||||
|
||||
onUnmounted(() => {
|
||||
if (intervalId) window.clearInterval(intervalId);
|
||||
});
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue