Skip to main content
You are viewing Pre-Alpha documentation.
Vuetify0 Logo
Theme
Mode
Accessibility
Vuetify
Vuetify One

Sign in to Vuetify One

Access premium tools across the Vuetify ecosystem — Bin, Play, Studio, and more.

Not a subscriber? See what's included

useMutationObserver

A composable for detecting DOM changes using the Mutation Observer API with automatic cleanup.


Advanced84.5% coverageMar 3, 2026

Usage

The useMutationObserver composable wraps the Mutation Observer API to detect changes to the DOM tree. It’s useful for monitoring attribute changes, child element modifications, and character data updates.

vue
<script setup lang="ts">
  import { useMutationObserver } from '@vuetify/v0'
  import { ref, useTemplateRef } from 'vue'

  const target = useTemplateRef('target')
  const mutationCount = ref(0)

  useMutationObserver(target, (mutations) => {
    mutationCount.value += mutations.length
    mutations.forEach(mutation => {
      console.log('Type:', mutation.type)
      console.log('Added nodes:', mutation.addedNodes)
      console.log('Removed nodes:', mutation.removedNodes)
    })
  }, {
    childList: true,
    attributes: true,
    attributeOldValue: true
  })
</script>

<template>
  <div>
    <div ref="target">
      <p>Mutations detected: {{ mutationCount }}</p>
    </div>
  </div>
</template>

Architecture

useMutationObserver wraps the native MutationObserver API with Vue reactivity:

Mutation Observer Hierarchy

Use controls to zoom and pan. Click outside or press Escape to close.

Mutation Observer Hierarchy

Reactivity

Property/MethodReactiveNotes
isActiveComputed from observer ref
isPausedShallowRef, readonly
targetAccepts MaybeRef, watched for changes

API Reference

The following API details are for the useMutationObserver composable.

Functions

useMutationObserver

(target: MaybeElementRef, callback: (entries: MutationObserverRecord[]) => void, options?: UseMutationObserverOptions) => UseMutationObserverReturn

A composable that uses the Mutation Observer API to detect changes in the DOM.

Options

immediate

boolean | undefined

once

boolean | undefined

childList

boolean | undefined

attributes

boolean | undefined

characterData

boolean | undefined

subtree

boolean | undefined

attributeOldValue

boolean | undefined

characterDataOldValue

boolean | undefined

attributeFilter

string[] | undefined

Properties

isActive

Readonly<Ref<boolean, boolean>>

Whether the observer is currently active (created and observing)

isPaused

Readonly<Ref<boolean, boolean>>

Whether the observer is currently paused

Methods

pause

() => void

Pause observation (disconnects observer but keeps it alive)

resume

() => void

Resume observation

stop

() => void

Stop observation and clean up (destroys observer)

Was this page helpful?

© 2016-1970 Vuetify, LLC
Ctrl+/