14 lines
354 B
TypeScript
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);
|
|
}
|
|
}
|