fix(nuxt): immediately call asyncData handler (#6472)

This commit is contained in:
Daniel Roe 2022-08-09 22:48:48 +01:00 committed by GitHub
parent fe26b943cc
commit 5232c1b5b4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -131,8 +131,14 @@ export function useAsyncData<
}
asyncData.pending.value = true
// TODO: Cancel previous promise
nuxt._asyncDataPromises[key] = Promise.resolve()
.then(() => handler(nuxt))
nuxt._asyncDataPromises[key] = new Promise<DataT>(
(resolve, reject) => {
try {
resolve(handler(nuxt))
} catch (err) {
reject(err)
}
})
.then((result) => {
if (options.transform) {
result = options.transform(result)