docs(plugins): add directive example (#5667)

Co-authored-by: Sébastien Chopin <seb@nuxtjs.com>
Co-authored-by: Daniel Roe <daniel@roe.dev>
This commit is contained in:
Paranoid 2022-07-07 03:10:29 +08:00 committed by GitHub
parent f09d1d88da
commit dd436eabae
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -122,4 +122,24 @@ export default defineNuxtPlugin((nuxtApp) => {
})
```
## Vue directives
Similarly, you can register a custom Vue directive in a plugin. For example, in `plugins/directive.ts`:
```ts
export default defineNuxtPlugin((nuxtApp) => {
nuxtApp.vueApp.directive('focus', {
mounted (el) {
el.focus()
},
getSSRProps (binding, vnode) {
// you can provide SSR-specific props here
return {}
}
})
})
```
:ReadMore{link="https://vuejs.org/guide/reusability/custom-directives.html"}
:LinkExample{link="/examples/app/plugins"}