Skip to content

Commit

Permalink
feat: add vuetify:ready hook (#112)
Browse files Browse the repository at this point in the history
* feat: add vuetify:created hook

* fix: coment in plugin docs

* chore: rename hook to vuetify:ready + add hook in playground

---------

Co-authored-by: Gábor Torma <gabor@torma.dev>
Co-authored-by: userquin <userquin@gmail.com>
  • Loading branch information
3 people committed Oct 4, 2023
1 parent 15e2d30 commit f880d9b
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 1 deletion.
11 changes: 11 additions & 0 deletions docs/guide/nuxt-plugin-hooks.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,14 @@ export default defineNuxtPlugin((nuxtApp) => {
})
})
```

If you need the Vuetify instance after creating it, you can use the `vuetify:ready` hook in your Nuxt Plugin:
```ts
import { defineNuxtPlugin } from '#imports'

export default defineNuxtPlugin((nuxtApp) => {
nuxtApp.hook('vuetify:ready', (vuetify) => {
// your logic here
})
})
```
3 changes: 3 additions & 0 deletions playground/plugins/vuetify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ export default defineNuxtPlugin((nuxtApp) => {
console.log('vuetify:plugin:hook', vuetifyOptions)
}
})
nuxtApp.hook('vuetify:ready', () => {
console.log('vuetify:ready')
})
nuxtApp.hook('vuetify:ssr-client-hints', ({ ssrClientHints }) => {
console.log('vuetify:ssr-client-hints', ssrClientHints)
})
Expand Down
2 changes: 2 additions & 0 deletions src/runtime/plugins/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ export async function configureVuetify() {

nuxtApp.provide('vuetify', vuetify)

await nuxtApp.hooks.callHook('vuetify:ready', vuetify)

if (process.client) {
// eslint-disable-next-line no-console
isDev && console.log('Vuetify 3 initialized', vuetify)
Expand Down
3 changes: 2 additions & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { LocaleOptions, RtlOptions, VuetifyOptions } from 'vuetify'
import type { LocaleOptions, RtlOptions, createVuetify, VuetifyOptions } from 'vuetify'
import type { UnwrapNestedRefs } from 'vue'

export type DateAdapter = 'vuetify' | 'date-fns' | 'moment' | 'luxon' | 'dayjs' | 'js-joda' | 'date-fns-jalali' | 'jalaali' | 'hijri' | 'custom'
Expand Down Expand Up @@ -380,6 +380,7 @@ declare module '#app' {
isDev: boolean
vuetifyOptions: VuetifyOptions
}) => Promise<void> | void
'vuetify:ready': (vuetify: ReturnType<typeof createVuetify>) => Promise<void> | void
'vuetify:ssr-client-hints': (options: {
vuetifyOptions: VuetifyOptions
ssrClientHints: SSRClientHints
Expand Down

0 comments on commit f880d9b

Please sign in to comment.