fix(nuxt): prefer nuxt app context over getCurrentInstance (#5456)

This commit is contained in:
Daniel Roe 2022-06-15 13:00:34 +01:00 committed by GitHub
parent 2fa0248cab
commit d7d97cd7d1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -236,17 +236,17 @@ export function callWithNuxt<T extends (...args: any[]) => any> (nuxt: NuxtApp |
* Returns the current Nuxt instance. * Returns the current Nuxt instance.
*/ */
export function useNuxtApp () { export function useNuxtApp () {
const vm = getCurrentInstance()
if (!vm) {
const nuxtAppInstance = nuxtAppCtx.use() const nuxtAppInstance = nuxtAppCtx.use()
if (!nuxtAppInstance) { if (!nuxtAppInstance) {
const vm = getCurrentInstance()
if (!vm) {
throw new Error('nuxt instance unavailable') throw new Error('nuxt instance unavailable')
} }
return nuxtAppInstance return vm.appContext.app.$nuxt as NuxtApp
} }
return vm.appContext.app.$nuxt as NuxtApp return nuxtAppInstance
} }
export function useRuntimeConfig (): RuntimeConfig { export function useRuntimeConfig (): RuntimeConfig {