Function app.directive()
Registers a global custom directive if passing
both a name string and a directive definition, or
retrieves an already registered one if only the
name is passed.
interface App {
directive(name: string): Directive | undefined
directive(name: string, directive: Directive): this
}
import { createApp } from 'vue'
const app = createApp({
/* ... */
})
// register (object directive)
app.directive('my-directive', {
/* custom directive hooks */
})
// register (function directive shorthand)
app.directive('my-directive', () => {
/* ... */
})
// retrieve a registered directive
const myDirective = app.directive('my-directive')