mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-17 03:14:46 +00:00
10 lines
366 B
TypeScript
10 lines
366 B
TypeScript
|
// @ts-expect-error withAsyncContext is internal API
|
||
|
import { getCurrentInstance, withAsyncContext as withVueAsyncContext } from 'vue'
|
||
|
|
||
|
export function withAsyncContext (fn: () => PromiseLike<unknown>) {
|
||
|
return withVueAsyncContext(() => {
|
||
|
const nuxtApp = getCurrentInstance()?.appContext.app.$nuxt
|
||
|
return nuxtApp ? nuxtApp.runWithContext(fn) : fn()
|
||
|
})
|
||
|
}
|