From 77893610dfe9596cdc8e56d87817da6dd805e780 Mon Sep 17 00:00:00 2001 From: Wick Date: Thu, 27 Feb 2025 10:37:31 +0800 Subject: [PATCH] refactor: migrate to getCurrentInstance API --- packages/runtime-core/src/apiInject.ts | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/packages/runtime-core/src/apiInject.ts b/packages/runtime-core/src/apiInject.ts index f05d7333d..1f5f19f9f 100644 --- a/packages/runtime-core/src/apiInject.ts +++ b/packages/runtime-core/src/apiInject.ts @@ -1,6 +1,5 @@ import { isFunction } from '@vue/shared' -import { currentInstance } from './component' -import { currentRenderingInstance } from './componentRenderContext' +import { currentInstance, getCurrentInstance } from './component' import { currentApp } from './apiCreateApp' import { warn } from './warning' @@ -51,7 +50,7 @@ export function inject( ) { // fallback to `currentRenderingInstance` so that this can be called in // a functional component - const instance = currentInstance || currentRenderingInstance + const instance = getCurrentInstance() // also support looking up from app-level provides w/ `app.runWithContext()` if (instance || currentApp) { @@ -88,5 +87,5 @@ export function inject( * user. One example is `useRoute()` in `vue-router`. */ export function hasInjectionContext(): boolean { - return !!(currentInstance || currentRenderingInstance || currentApp) + return !!(getCurrentInstance() || currentApp) }