Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(runtime-core): return the exposeProxy from mount #4606

Merged
merged 1 commit into from Sep 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
22 changes: 21 additions & 1 deletion packages/runtime-core/__tests__/apiExpose.spec.ts
@@ -1,4 +1,4 @@
import { nodeOps, render } from '@vue/runtime-test'
import { createApp, nodeOps, render } from '@vue/runtime-test'
import { defineComponent, h, ref } from '../src'

describe('api: expose', () => {
Expand Down Expand Up @@ -170,6 +170,26 @@ describe('api: expose', () => {
render(h(Parent), root)
})

test('with mount', () => {
const Component = defineComponent({
setup(_, { expose }) {
expose({
foo: 1
})
return {
bar: 2
}
},
render() {
return h('div')
}
})
const root = nodeOps.createElement('div')
const vm = createApp(Component).mount(root) as any
expect(vm.foo).toBe(1)
expect(vm.bar).toBe(undefined)
})

test('expose should allow access to built-in instance properties', () => {
const GrandChild = defineComponent({
render() {
Expand Down
5 changes: 3 additions & 2 deletions packages/runtime-core/src/apiCreateApp.ts
Expand Up @@ -3,7 +3,8 @@ import {
Data,
validateComponentName,
Component,
ComponentInternalInstance
ComponentInternalInstance,
getExposeProxy
} from './component'
import {
ComponentOptions,
Expand Down Expand Up @@ -309,7 +310,7 @@ export function createAppAPI<HostElement>(
devtoolsInitApp(app, version)
}

return vnode.component!.proxy
return getExposeProxy(vnode.component!) || vnode.component!.proxy
} else if (__DEV__) {
warn(
`App has already been mounted.\n` +
Expand Down