Skip to content
This repository has been archived by the owner on Apr 6, 2023. It is now read-only.

docs(plugins): add directive example #5667

Merged
merged 5 commits into from
Jul 6, 2022
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 directive
danielroe marked this conversation as resolved.
Show resolved Hide resolved

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"}

danielroe marked this conversation as resolved.
Show resolved Hide resolved
:LinkExample{link="/examples/app/plugins"}