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/createDisposableDirective.md
1---2category: Utilities3---45# createDisposableDirective67Utility for authoring disposable directives. Reactive effects created within `mounted` directive hook will be tracked and automatically disposed when directive is unmounted.89## Usage1011Creating a directive that uses `createDisposableDirective`1213```ts14import { useMouse } from '@vueuse/core'15import { createDisposableDirective } from '@vueuse/shared'1617export const VDirective = createDisposableDirective({18mounted(el, binding) {19const value = binding.value20if (typeof value === 'function') {21// `useMouse` event listener will be removed automatically when directive is unmounted22const { x, y } = useMouse()23watch(x, val => value(val))24}25}26})27```2829## Type Declarations3031```ts32type originDirective<H, V, A> =33| FunctionDirective<H, V, string, A>34| ObjectDirective<H, V, string, A>35/**36* Utility for authoring disposable directives. Reactive effects created within `mounted` directive hook will be tracked and automatically disposed when directive is unmounted.37*38* @see https://vueuse.org/createDisposableDirective39*40* @__NO_SIDE_EFFECTS__41*/42export declare function createDisposableDirective<43H extends HTMLElement,44V,45A = any,46>(origin?: originDirective<H, V, A>): originDirective<H, V, A>47```48