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/useMutationObserver.md
1---2category: Elements3---45# useMutationObserver67Watch for changes being made to the DOM tree. [MutationObserver MDN](https://developer.mozilla.org/en-US/docs/Web/API/MutationObserver)89## Usage1011```vue12<script setup lang="ts">13import { useMutationObserver } from '@vueuse/core'14import { ref, useTemplateRef } from 'vue'1516const el = useTemplateRef('el')17const messages = ref([])1819useMutationObserver(el, (mutations) => {20if (mutations[0])21messages.value.push(mutations[0].attributeName)22}, {23attributes: true,24})25</script>2627<template>28<div ref="el">29Hello VueUse30</div>31</template>32```3334## Type Declarations3536```ts37export interface UseMutationObserverOptions38extends MutationObserverInit, ConfigurableWindow {}39export interface UseMutationObserverReturn extends Supportable {40stop: () => void41takeRecords: () => MutationRecord[] | undefined42}43/**44* Watch for changes being made to the DOM tree.45*46* @see https://vueuse.org/useMutationObserver47* @see https://developer.mozilla.org/en-US/docs/Web/API/MutationObserver MutationObserver MDN48* @param target49* @param callback50* @param options51*/52export declare function useMutationObserver(53target:54| MaybeComputedElementRef55| MaybeComputedElementRef[]56| MaybeRefOrGetter<MaybeElement[]>,57callback: MutationCallback,58options?: UseMutationObserverOptions,59): UseMutationObserverReturn60```61