skills/vueuse-functions/references/useCurrentElement.md
Get the DOM element of current component as a ref.
import { useCurrentElement } from '@vueuse/core'
const el = useCurrentElement() // ComputedRef<Element>
Or pass a specific vue component
<script setup lang="ts">
import { useCurrentElement, VueInstance } from '@vueuse/core'
import { shallowRef } from 'vue'
const componentRef = shallowRef<VueInstance>(null as unknown as VueInstance)
const el = useCurrentElement(componentRef) // ComputedRef<Element>
</script>
<template>
<div>
<OtherVueComponent ref="componentRef" />
<p>Hello world</p>
</div>
</template>
This functions uses $el under the hood.
Value of the ref will be undefined until the component is mounted.
It's recommend to only use this function for components with a single root element.
export declare function useCurrentElement<
T extends MaybeElement = MaybeElement,
R extends VueInstance = VueInstance,
E extends MaybeElement = MaybeElement extends T
? IsAny<R["$el"]> extends false
? R["$el"]
: T
: T,
>(rootComponent?: MaybeElementRef<R>): ComputedRefWithControl<E>