Skip to content

Commit

Permalink
docs(plugins): add directive example (nuxt#5667)
Browse files Browse the repository at this point in the history
Co-authored-by: Sébastien Chopin <seb@nuxtjs.com>
Co-authored-by: Daniel Roe <daniel@roe.dev>
  • Loading branch information
3 people authored Jul 6, 2022
1 parent f09d1d8 commit dd436ea
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions docs/content/2.guide/3.directory-structure/11.plugins.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"}

0 comments on commit dd436ea

Please sign in to comment.