File tree 2 files changed +59
-5
lines changed
2 files changed +59
-5
lines changed Original file line number Diff line number Diff line change @@ -95,4 +95,50 @@ describe('api: expose', () => {
95
95
expect ( childRef . value . bar ) . toBe ( 2 )
96
96
expect ( childRef . value . baz ) . toBeUndefined ( )
97
97
} )
98
+
99
+ test ( 'options: empty' , ( ) => {
100
+ const Child = defineComponent ( {
101
+ render ( ) { } ,
102
+ expose : [ ] ,
103
+ data ( ) {
104
+ return {
105
+ foo : 1
106
+ }
107
+ }
108
+ } )
109
+
110
+ const childRef = ref ( )
111
+ const Parent = {
112
+ setup ( ) {
113
+ return ( ) => h ( Child , { ref : childRef } )
114
+ }
115
+ }
116
+ const root = nodeOps . createElement ( 'div' )
117
+ render ( h ( Parent ) , root )
118
+ expect ( childRef . value ) . toBeTruthy ( )
119
+ expect ( 'foo' in childRef . value ) . toBe ( false )
120
+ } )
121
+
122
+ test ( 'options: empty + setup context' , ( ) => {
123
+ const Child = defineComponent ( {
124
+ render ( ) { } ,
125
+ expose : [ ] ,
126
+ setup ( _ , { expose } ) {
127
+ expose ( {
128
+ foo : 1
129
+ } )
130
+ }
131
+ } )
132
+
133
+ const childRef = ref ( )
134
+ const Parent = {
135
+ setup ( ) {
136
+ return ( ) => h ( Child , { ref : childRef } )
137
+ }
138
+ }
139
+ const root = nodeOps . createElement ( 'div' )
140
+ render ( h ( Parent ) , root )
141
+ expect ( childRef . value ) . toBeTruthy ( )
142
+ expect ( childRef . value . foo ) . toBe ( 1 )
143
+ } )
98
144
} )
Original file line number Diff line number Diff line change @@ -743,11 +743,19 @@ export function applyOptions(
743
743
onUnmounted ( unmounted . bind ( publicThis ) )
744
744
}
745
745
746
- if ( ! asMixin && expose ) {
747
- const exposed = instance . exposed || ( instance . exposed = proxyRefs ( { } ) )
748
- expose . forEach ( key => {
749
- exposed [ key ] = toRef ( publicThis , key as any )
750
- } )
746
+ if ( isArray ( expose ) ) {
747
+ if ( ! asMixin ) {
748
+ if ( expose . length ) {
749
+ const exposed = instance . exposed || ( instance . exposed = proxyRefs ( { } ) )
750
+ expose . forEach ( key => {
751
+ exposed [ key ] = toRef ( publicThis , key as any )
752
+ } )
753
+ } else if ( ! instance . exposed ) {
754
+ instance . exposed = EMPTY_OBJ
755
+ }
756
+ } else if ( __DEV__ ) {
757
+ warn ( `The \`expose\` option is ignored when used in mixins.` )
758
+ }
751
759
}
752
760
}
753
761
You can’t perform that action at this time.
0 commit comments