mirror of
https://github.com/nuxt/ui.git
synced 2026-09-14 19:51:10 +08:00
16 lines
555 B
TypeScript
16 lines
555 B
TypeScript
export function useFetchComponentExample(name: string) {
|
|
if (import.meta.server) {
|
|
const event = useRequestEvent()
|
|
event?.node.res.setHeader(
|
|
'x-nitro-prerender',
|
|
[event?.node.res.getHeader('x-nitro-prerender'), `/api/component-example/${name}.json`].filter(Boolean).join(',')
|
|
)
|
|
}
|
|
|
|
return useAsyncData(`component-example-${name}`, () => $fetch(`/api/component-example/${name}.json`).catch(() => ({})), {
|
|
lazy: import.meta.client,
|
|
dedupe: 'defer',
|
|
getCachedData: (key, nuxtApp) => nuxtApp.payload.data[key]
|
|
})
|
|
}
|