← All notes

Register a Vue custom directive for low-level DOM access

Answer: Vue ships core directives such as v-model and v-show, and you can register your own custom directives. They are aimed at reusing logic that needs low-level DOM access on plain elements, not at replacing components or composables.

Hooks on the element

A custom directive is an object of lifecycle hooks, similar to a component. Those hooks receive the element the directive is bound to. Components remain the main building blocks, and composables reuse stateful logic. One example directive adds a class to an element.

Global registration

app.directive on the application instance registers a global custom directive when you pass a name string and a directive definition. If you pass only the name, it retrieves an already registered directive. app.directive registers the directive on the application instance.

| custom directives | app.directive | |---|---| | v-model and v-show | Default directives shipped in core | | custom directive | Object of lifecycle hooks bound to an element | | components and composables | Main reuse tools beside directives | | app.directive | Registers or retrieves a global directive |

See also

Claims

Sources

License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: Vue docs, Custom Directives; Vue docs, Application API. CC-BY-4.0; CC-BY-4.0. Text was condensed and changed from the originals.

License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: Vue docs, Custom Directives; Vue docs, Application API. CC-BY-4.0; CC-BY-4.0.

Cite this

Permanent ID: iil:note:fa9at1ky

iinventedlight. 2026. "Register a Vue custom directive for low-level DOM access." iinventedlight Library, iil:note:fa9at1ky, version of 2026-11-19. https://iinventedlight.com/library/notes/vue-custom-directives/. License: CC-BY-4.0.

@misc{iil_note_fa9at1ky,
  author = {{iinventedlight}},
  title = {{Register a Vue custom directive for low-level DOM access}},
  howpublished = {iinventedlight Library},
  year = {2026},
  date = {2026-11-19},
  url = {https://iinventedlight.com/library/notes/vue-custom-directives/},
  note = {Permanent ID iil:note:fa9at1ky. License: CC-BY-4.0.},
}

Markdown

Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com. Or Report a correction (no account needed).

Extra files beside this note

These files use this note's license, shown below. Paper extras retain their reproduction status; a link is not a reproduction.

All artifact files (JSON index)

For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/vue-custom-directives.md.