Skip to content

Commit 5aa4255

Browse files
fix(runtime-core): return the exposeProxy from mount (#4606)
1 parent 2ca45dc commit 5aa4255

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

packages/runtime-core/__tests__/apiExpose.spec.ts

+21-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { nodeOps, render } from '@vue/runtime-test'
1+
import { createApp, nodeOps, render } from '@vue/runtime-test'
22
import { defineComponent, h, ref } from '../src'
33

44
describe('api: expose', () => {
@@ -170,6 +170,26 @@ describe('api: expose', () => {
170170
render(h(Parent), root)
171171
})
172172

173+
test('with mount', () => {
174+
const Component = defineComponent({
175+
setup(_, { expose }) {
176+
expose({
177+
foo: 1
178+
})
179+
return {
180+
bar: 2
181+
}
182+
},
183+
render() {
184+
return h('div')
185+
}
186+
})
187+
const root = nodeOps.createElement('div')
188+
const vm = createApp(Component).mount(root) as any
189+
expect(vm.foo).toBe(1)
190+
expect(vm.bar).toBe(undefined)
191+
})
192+
173193
test('expose should allow access to built-in instance properties', () => {
174194
const GrandChild = defineComponent({
175195
render() {

packages/runtime-core/src/apiCreateApp.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ import {
33
Data,
44
validateComponentName,
55
Component,
6-
ComponentInternalInstance
6+
ComponentInternalInstance,
7+
getExposeProxy
78
} from './component'
89
import {
910
ComponentOptions,
@@ -309,7 +310,7 @@ export function createAppAPI<HostElement>(
309310
devtoolsInitApp(app, version)
310311
}
311312

312-
return vnode.component!.proxy
313+
return getExposeProxy(vnode.component!) || vnode.component!.proxy
313314
} else if (__DEV__) {
314315
warn(
315316
`App has already been mounted.\n` +

0 commit comments

Comments
 (0)