mirror of
https://github.com/ArthurDanjou/ui.git
synced 2026-01-30 19:57:55 +01:00
feat(module): add support for vue using unplugin (#2416)
Co-authored-by: Benjamin Canac <canacb1@gmail.com>
This commit is contained in:
36
src/runtime/vue/stubs.ts
Normal file
36
src/runtime/vue/stubs.ts
Normal file
@@ -0,0 +1,36 @@
|
||||
import { ref } from 'vue'
|
||||
import type { Ref, Plugin as VuePlugin } from 'vue'
|
||||
|
||||
import appConfig from '#build/app.config'
|
||||
import type { NuxtApp } from '#app'
|
||||
|
||||
export { useHead } from '@unhead/vue'
|
||||
export { useRoute, useRouter } from 'vue-router'
|
||||
|
||||
export const useAppConfig = () => appConfig
|
||||
|
||||
const state: Record<string, any> = {}
|
||||
|
||||
export const useState = <T>(key: string, init: () => T): Ref<T> => {
|
||||
if (state[key]) {
|
||||
return state[key] as Ref<T>
|
||||
}
|
||||
const value = ref(init())
|
||||
state[key] = value
|
||||
return value as Ref<T>
|
||||
}
|
||||
|
||||
export function useNuxtApp() {
|
||||
return {
|
||||
isHydrating: true,
|
||||
payload: { serverRendered: false }
|
||||
}
|
||||
}
|
||||
|
||||
export function defineNuxtPlugin(plugin: (nuxtApp: NuxtApp) => void) {
|
||||
return {
|
||||
install(app) {
|
||||
plugin({ vueApp: app } as NuxtApp)
|
||||
}
|
||||
} satisfies VuePlugin
|
||||
}
|
||||
Reference in New Issue
Block a user