mirror of
https://github.com/nuxt/nuxt.git
synced 2025-01-18 01:15:58 +00:00
fix(nuxt3): handle legacy asyncData
(options api) as ref
(#2668)
This commit is contained in:
parent
59e5cfea39
commit
7479eacaac
@ -1,4 +1,4 @@
|
|||||||
import { defineComponent, getCurrentInstance, toRefs } from 'vue'
|
import { defineComponent, getCurrentInstance, reactive, toRefs } from 'vue'
|
||||||
import type { DefineComponent } from 'vue'
|
import type { DefineComponent } from 'vue'
|
||||||
import { useRoute } from 'vue-router'
|
import { useRoute } from 'vue-router'
|
||||||
import type { LegacyContext } from '../compat/legacy-app'
|
import type { LegacyContext } from '../compat/legacy-app'
|
||||||
@ -14,7 +14,11 @@ async function runLegacyAsyncData (res: Record<string, any> | Promise<Record<str
|
|||||||
const { fetchKey } = vm.proxy.$options
|
const { fetchKey } = vm.proxy.$options
|
||||||
const key = typeof fetchKey === 'function' ? fetchKey(() => '') : fetchKey || route.fullPath
|
const key = typeof fetchKey === 'function' ? fetchKey(() => '') : fetchKey || route.fullPath
|
||||||
const { data } = await useAsyncData(`options:asyncdata:${key}`, () => fn(nuxt._legacyContext))
|
const { data } = await useAsyncData(`options:asyncdata:${key}`, () => fn(nuxt._legacyContext))
|
||||||
Object.assign(await res, toRefs(data))
|
if (data.value && typeof data.value === 'object') {
|
||||||
|
Object.assign(await res, toRefs(reactive(data.value)))
|
||||||
|
} else if (process.dev) {
|
||||||
|
console.warn('[nuxt] asyncData should return an object', data)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const defineNuxtComponent: typeof defineComponent =
|
export const defineNuxtComponent: typeof defineComponent =
|
||||||
|
Loading…
Reference in New Issue
Block a user