fix(nuxt): don't override vue instance with legacy `asyncData` (#28842)

This commit is contained in:
Daniel Roe 2024-09-05 08:56:01 +01:00
parent 74985a5251
commit 468ab2dc0b
No known key found for this signature in database
GPG Key ID: 3714AB03996F442B
1 changed files with 1 additions and 1 deletions

View File

@ -16,7 +16,7 @@ async function runLegacyAsyncData (res: Record<string, any> | Promise<Record<str
const { fetchKey, _fetchKeyBase } = vm.proxy!.$options const { fetchKey, _fetchKeyBase } = vm.proxy!.$options
const key = (typeof fetchKey === 'function' ? fetchKey(() => '') : fetchKey) || const key = (typeof fetchKey === 'function' ? fetchKey(() => '') : fetchKey) ||
([_fetchKeyBase, route.fullPath, route.matched.findIndex(r => Object.values(r.components || {}).includes(vm.type))].join(':')) ([_fetchKeyBase, route.fullPath, route.matched.findIndex(r => Object.values(r.components || {}).includes(vm.type))].join(':'))
const { data, error } = await useAsyncData(`options:asyncdata:${key}`, () => nuxtApp.runWithContext(() => fn(nuxtApp))) const { data, error } = await useAsyncData(`options:asyncdata:${key}`, () => import.meta.server ? nuxtApp.runWithContext(() => fn(nuxtApp)) : fn(nuxtApp))
if (error.value) { if (error.value) {
throw createError(error.value) throw createError(error.value)
} }