File tree Expand file tree Collapse file tree 3 files changed +20
-6
lines changed Expand file tree Collapse file tree 3 files changed +20
-6
lines changed Original file line number Diff line number Diff line change @@ -145,7 +145,7 @@ export declare interface ComponentInternalInstance {
145
145
isDeactivated : boolean
146
146
}
147
147
148
- export function getCurrentVu2Instance ( ) {
148
+ export function getCurrentVue2Instance ( ) {
149
149
return currentInstance
150
150
}
151
151
@@ -173,6 +173,9 @@ function toVue3ComponentInstance(
173
173
update : vue2Instance . $forceUpdate ,
174
174
uid : vue2Instance . _uid ,
175
175
176
+ // $emit is defined on prototype and it expected to be bound
177
+ emit : vue2Instance . $emit . bind ( vue2Instance ) ,
178
+
176
179
parent : null ,
177
180
root : null as any ,
178
181
} as unknown ) as ComponentInternalInstance
@@ -183,7 +186,6 @@ function toVue3ComponentInstance(
183
186
'props' ,
184
187
'attrs' ,
185
188
'refs' ,
186
- 'emit' ,
187
189
'vnode' ,
188
190
'slots' ,
189
191
] as const
Original file line number Diff line number Diff line change 1
1
import { ComponentInstance } from '../component'
2
2
import vmStateManager from './vmStateManager'
3
- import { setCurrentInstance , getCurrentVu2Instance } from '../runtimeContext'
3
+ import { setCurrentInstance , getCurrentVue2Instance } from '../runtimeContext'
4
4
import { Ref , isRef } from '../apis'
5
5
import { hasOwn , proxy , warn } from './utils'
6
6
import { createSlotProxy , resolveSlots } from './helper'
@@ -112,7 +112,7 @@ export function activateCurrentInstance(
112
112
fn : ( vm_ : ComponentInstance ) => any ,
113
113
onError ?: ( err : Error ) => void
114
114
) {
115
- let preVm = getCurrentVu2Instance ( )
115
+ let preVm = getCurrentVue2Instance ( )
116
116
setCurrentInstance ( vm )
117
117
try {
118
118
return fn ( vm )
Original file line number Diff line number Diff line change @@ -45,7 +45,12 @@ describe('component: proxy', () => {
45
45
components : {
46
46
Comp,
47
47
} ,
48
- template : '<Comp/>' ,
48
+ data ( ) {
49
+ return {
50
+ update : 0 ,
51
+ }
52
+ } ,
53
+ template : '<Comp @update="update++"/>' ,
49
54
}
50
55
const app = createApp ( Parent ) . mount ( document . createElement ( 'div' ) )
51
56
@@ -60,10 +65,17 @@ describe('component: proxy', () => {
60
65
instance ! . parent && instance ! . parent . proxy
61
66
)
62
67
expect ( instanceProxy . $root ) . toBe ( instance ! . root . proxy )
63
- expect ( instanceProxy . $emit ) . toBe ( instance ! . emit )
64
68
expect ( instance . isMounted ) . toBe ( true )
65
69
expect ( instance . isUnmounted ) . toBe ( false )
66
70
71
+ // @ts -expect-error no typings
72
+ expect ( app . update ) . toBe ( 0 )
73
+
74
+ instance ! . emit ( 'update' )
75
+
76
+ // @ts -expect-error no typings
77
+ expect ( app . update ) . toBe ( 1 )
78
+
67
79
// expect(instanceProxy.$el).toBe(instance!.vnode.el)
68
80
// expect(instanceProxy.$options).toBe(instance!.type)
69
81
You can’t perform that action at this time.
0 commit comments