mirror of
https://github.com/nuxt/nuxt.git
synced 2024-12-04 19:37:18 +00:00
11 lines
386 B
TypeScript
11 lines
386 B
TypeScript
// @ts-expect-error withAsyncContext is internal API
|
|
import { getCurrentInstance, withAsyncContext as withVueAsyncContext } from 'vue'
|
|
|
|
/** @since 3.8.0 */
|
|
export function withAsyncContext (fn: () => PromiseLike<unknown>) {
|
|
return withVueAsyncContext(() => {
|
|
const nuxtApp = getCurrentInstance()?.appContext.app.$nuxt
|
|
return nuxtApp ? nuxtApp.runWithContext(fn) : fn()
|
|
})
|
|
}
|