Просмотр исходного кода

dx(runtime-core): fix warning message for useSlots, useAttrs invocation with missing instance (#13647)

Alex Snezhko 9 месяцев назад
Родитель
Сommit
7343f7c95f
1 измененных файлов с 4 добавлено и 4 удалено
  1. 4 4
      packages/runtime-core/src/apiSetupHelpers.ts

+ 4 - 4
packages/runtime-core/src/apiSetupHelpers.ts

@@ -382,17 +382,17 @@ export function withDefaults<
 }
 
 export function useSlots(): SetupContext['slots'] {
-  return getContext().slots
+  return getContext('useSlots').slots
 }
 
 export function useAttrs(): SetupContext['attrs'] {
-  return getContext().attrs
+  return getContext('useAttrs').attrs
 }
 
-function getContext(): SetupContext {
+function getContext(calledFunctionName: string): SetupContext {
   const i = getCurrentInstance()!
   if (__DEV__ && !i) {
-    warn(`useContext() called without active instance.`)
+    warn(`${calledFunctionName}() called without active instance.`)
   }
   return i.setupContext || (i.setupContext = createSetupContext(i))
 }