mirror of
https://github.com/ArthurDanjou/ui.git
synced 2026-01-14 12:14:41 +01:00
fix(vue): mock nuxtApp.hooks & useRuntimeHook
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import { ref } from 'vue'
|
||||
import { ref, onScopeDispose } from 'vue'
|
||||
import type { Ref, Plugin as VuePlugin } from 'vue'
|
||||
import { createHooks } from 'hookable'
|
||||
|
||||
import appConfig from '#build/app.config'
|
||||
import type { NuxtApp } from '#app'
|
||||
@@ -58,13 +59,25 @@ export const useState = <T>(key: string, init: () => T): Ref<T> => {
|
||||
return value as Ref<T>
|
||||
}
|
||||
|
||||
const hooks = createHooks()
|
||||
|
||||
export function useNuxtApp() {
|
||||
return {
|
||||
isHydrating: true,
|
||||
payload: { serverRendered: false }
|
||||
payload: { serverRendered: false },
|
||||
hooks,
|
||||
hook: hooks.hook
|
||||
}
|
||||
}
|
||||
|
||||
export function useRuntimeHook(name: string, fn: (...args: any[]) => void): void {
|
||||
const nuxtApp = useNuxtApp()
|
||||
|
||||
const unregister = nuxtApp.hook(name, fn)
|
||||
|
||||
onScopeDispose(unregister)
|
||||
}
|
||||
|
||||
export function defineNuxtPlugin(plugin: (nuxtApp: NuxtApp) => void) {
|
||||
return {
|
||||
install(app) {
|
||||
|
||||
Reference in New Issue
Block a user