chore: use deeper import for use nuxt app + convert to async function

This commit is contained in:
Daniel Roe 2025-01-01 22:59:53 +00:00
parent f9b6966f3e
commit 6530e7a5e6
No known key found for this signature in database
GPG Key ID: CBC814C393D93268

View File

@ -1,19 +1,19 @@
import { h, onMounted, ref } from 'vue'
import type { AsyncComponentLoader, ComponentOptions } from 'vue'
import { isPromise } from '@vue/shared' import { isPromise } from '@vue/shared'
import { type AsyncComponentLoader, type ComponentOptions, h, onMounted, ref } from 'vue' import { useNuxtApp } from '#app/nuxt'
import { useNuxtApp } from '#app'
import ServerPlaceholder from '#app/components/server-placeholder' import ServerPlaceholder from '#app/components/server-placeholder'
/* @__NO_SIDE_EFFECTS__ */ /* @__NO_SIDE_EFFECTS__ */
export const createClientPage = (loader: AsyncComponentLoader) => { export async function createClientPage (loader: AsyncComponentLoader) {
// Vue-router: Write "() => import('./MyPage.vue')" instead of "defineAsyncComponent(() => import('./MyPage.vue'))". // vue-router: Write "() => import('./MyPage.vue')" instead of "defineAsyncComponent(() => import('./MyPage.vue'))".
return loader().then((m) => { const m = await loader()
const c = m.default || m const c = m.default || m
if (import.meta.dev) { if (import.meta.dev) {
// mark component as client-only for `definePageMeta` // mark component as client-only for `definePageMeta`
c.__clientOnlyPage = true c.__clientOnlyPage = true
} }
return pageToClientOnly(c) return pageToClientOnly(c)
})
} }
const cache = new WeakMap() const cache = new WeakMap()