Files
workspace/code/email/Email-Vue/src/hooks/useOnceMounted.ts
T
2025-06-10 21:27:20 +08:00

14 lines
354 B
TypeScript

// composables/useOnceMounted.ts
import { onMounted, getCurrentInstance } from "vue";
export function useOnceMounted(callback: () => void) {
const instance = getCurrentInstance();
const key = `__mounted_once_${instance?.type.__file || Math.random()}`;
if (!(window as any)[key]) {
(window as any)[key] = true;
onMounted(callback);
}
}