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
- id: C1 claim: Besides core directives such as v-model and v-show, Vue lets you register custom directives. source: S1 evidence: "register your own custom directives"
- id: C2 claim: Custom directives are meant for reuse of low-level DOM access on plain elements. source: S1 evidence: "low-level DOM access on plain elements"
- id: C3 claim: app.directive registers a global custom directive, or retrieves one by name. source: S2 evidence: "Registers a global custom directive"
Sources
- [S1] Custom Directives. Vue docs. https://vuejs.org/guide/reusability/custom-directives.html . License: CC-BY-4.0. Accessed 2026-11-19.
- [S2] Application API. Vue docs. https://vuejs.org/api/application.html . License: CC-BY-4.0. Accessed 2026-11-19.
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
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.},
}
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.
- vue-custom-directives.table.json (table; CC-BY-4.0)
- vue-custom-directives.schema.json (schema; CC-BY-4.0)
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.