(wait?: 'tick' | 'frame')
| 1 | import { nextTick, onBeforeUnmount, onMounted, readonly, ref } from 'vue' |
| 2 | |
| 3 | export function useMounted(wait?: 'tick' | 'frame') { |
| 4 | const isMounted = ref(false) |
| 5 | |
| 6 | const mount = () => (isMounted.value = true) |
| 7 | |
| 8 | onMounted(() => { |
| 9 | if (wait === 'tick') { |
| 10 | nextTick(mount) |
| 11 | } else if (wait === 'frame') { |
| 12 | requestAnimationFrame(mount) |
| 13 | } else { |
| 14 | mount() |
| 15 | } |
| 16 | }) |
| 17 | |
| 18 | onBeforeUnmount(() => { |
| 19 | isMounted.value = false |
| 20 | }) |
| 21 | |
| 22 | return { isMounted: readonly(isMounted) } |
| 23 | } |
no test coverage detected