mirror of
https://github.com/nuxt/nuxt.git
synced 2025-01-19 01:45:53 +00:00
fix(nuxt): prefer nuxt app context over getCurrentInstance
(#5456)
This commit is contained in:
parent
2fa0248cab
commit
d7d97cd7d1
@ -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()
|
const nuxtAppInstance = nuxtAppCtx.use()
|
||||||
|
|
||||||
if (!vm) {
|
if (!nuxtAppInstance) {
|
||||||
const nuxtAppInstance = nuxtAppCtx.use()
|
const vm = getCurrentInstance()
|
||||||
if (!nuxtAppInstance) {
|
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 {
|
||||||
|
Loading…
Reference in New Issue
Block a user