Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Apply VueUse composables in Vue 3/Nuxt projects to replace custom implementations with battle-tested utilities.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
references/useParentElement.md
1---2category: Elements3---45# useParentElement67Get parent element of the given element89## Usage1011When no argument is passed, it will return the parent element of the current component.1213```vue14<script setup lang="ts">15import { useParentElement } from '@vueuse/core'1617const parentEl = useParentElement()1819onMounted(() => {20console.log(parentEl.value)21})22</script>23```2425It can also accept a `ref` as the first argument.2627```vue28<script setup lang="ts">29import { useParentElement } from '@vueuse/core'30import { useTemplateRef } from 'vue'3132const tooltip = useTemplateRef('tooltip')3334const tooltipWrapper = useParentElement(tooltip)3536onMounted(() => {37console.log(tooltipWrapper.value)38})39</script>4041<template>42<div>43<p ref="tooltip" />44</div>45</template>46```4748## Type Declarations4950```ts51export declare function useParentElement(52element?: MaybeRefOrGetter<HTMLElement | SVGElement | null | undefined>,53): Readonly<ShallowRef<HTMLElement | SVGElement | null | undefined>>54```55