File tree Expand file tree Collapse file tree 1 file changed +26
-35
lines changed
packages/runtime-core/src Expand file tree Collapse file tree 1 file changed +26
-35
lines changed Original file line number Diff line number Diff line change @@ -36,6 +36,18 @@ export type ComponentPublicInstance<
36
36
ExtractComputedReturns < C > &
37
37
M
38
38
39
+ const publicPropertiesMap = {
40
+ $data : 'data' ,
41
+ $props : 'propsProxy' ,
42
+ $attrs : 'attrs' ,
43
+ $slots : 'slots' ,
44
+ $refs : 'refs' ,
45
+ $parent : 'parent' ,
46
+ $root : 'root' ,
47
+ $emit : 'emit' ,
48
+ $options : 'type'
49
+ }
50
+
39
51
export const PublicInstanceProxyHandlers = {
40
52
get ( target : ComponentInternalInstance , key : string ) {
41
53
const { renderContext, data, props, propsProxy } = target
@@ -46,44 +58,23 @@ export const PublicInstanceProxyHandlers = {
46
58
} else if ( hasOwn ( props , key ) ) {
47
59
// return the value from propsProxy for ref unwrapping and readonly
48
60
return propsProxy ! [ key ]
49
- } else {
50
- // TODO simplify this?
61
+ } else if ( key === '$el' ) {
62
+ return target . vnode . el
63
+ } else if ( hasOwn ( publicPropertiesMap , key ) ) {
64
+ return target [ publicPropertiesMap [ key ] ]
65
+ }
66
+ // methods are only exposed when options are supported
67
+ if ( __FEATURE_OPTIONS__ ) {
51
68
switch ( key ) {
52
- case '$data' :
53
- return data
54
- case '$props' :
55
- return propsProxy
56
- case '$attrs' :
57
- return target . attrs
58
- case '$slots' :
59
- return target . slots
60
- case '$refs' :
61
- return target . refs
62
- case '$parent' :
63
- return target . parent
64
- case '$root' :
65
- return target . root
66
- case '$emit' :
67
- return target . emit
68
- case '$el' :
69
- return target . vnode . el
70
- case '$options' :
71
- return target . type
72
- default :
73
- // methods are only exposed when options are supported
74
- if ( __FEATURE_OPTIONS__ ) {
75
- switch ( key ) {
76
- case '$forceUpdate' :
77
- return target . update
78
- case '$nextTick' :
79
- return nextTick
80
- case '$watch' :
81
- return instanceWatch . bind ( target )
82
- }
83
- }
84
- return target . user [ key ]
69
+ case '$forceUpdate' :
70
+ return target . update
71
+ case '$nextTick' :
72
+ return nextTick
73
+ case '$watch' :
74
+ return instanceWatch . bind ( target )
85
75
}
86
76
}
77
+ return target . user [ key ]
87
78
} ,
88
79
// this trap is only called in browser-compiled render functions that use
89
80
// `with (this) {}`
You can’t perform that action at this time.
0 commit comments