Maxim Mironjuk
-
April 24, 2026
Vue already ships the most important built-in directives, v-if, v-for and v-model among them, but some requirements cannot be covered by these because they need direct, reusable access to the raw DOM element. Detecting a click outside an element, auto-focusing an input, or initializing an element through a third-party tooltip library are classic cases for a custom directive. The app.directive() API lets you register such a directive globally and then use it in any component with a v-prefix just like a built-in directive, complete with its own lifecycle and a typed binding object.