File tree 2 files changed +13
-3
lines changed
packages/runtime-core/src
2 files changed +13
-3
lines changed Original file line number Diff line number Diff line change 1
- import { getCurrentInstance , SetupContext } from './component'
1
+ import {
2
+ getCurrentInstance ,
3
+ SetupContext ,
4
+ createSetupContext
5
+ } from './component'
2
6
import { EmitFn , EmitsOptions } from './componentEmits'
3
7
import { ComponentObjectPropsOptions , ExtractPropTypes } from './componentProps'
4
8
import { warn } from './warning'
@@ -53,5 +57,9 @@ export function defineEmit(emitOptions?: any) {
53
57
}
54
58
55
59
export function useContext ( ) : SetupContext {
56
- return getCurrentInstance ( ) ! . setupContext !
60
+ const i = getCurrentInstance ( ) !
61
+ if ( __DEV__ && ! i ) {
62
+ warn ( `useContext() called without active instance.` )
63
+ }
64
+ return i . setupContext || ( i . setupContext = createSetupContext ( i ) )
57
65
}
Original file line number Diff line number Diff line change @@ -746,7 +746,9 @@ const attrHandlers: ProxyHandler<Data> = {
746
746
}
747
747
}
748
748
749
- function createSetupContext ( instance : ComponentInternalInstance ) : SetupContext {
749
+ export function createSetupContext (
750
+ instance : ComponentInternalInstance
751
+ ) : SetupContext {
750
752
const expose : SetupContext [ 'expose' ] = exposed => {
751
753
if ( __DEV__ && instance . exposed ) {
752
754
warn ( `expose() should be called only once per setup().` )
You can’t perform that action at this time.
0 commit comments