fix(runtime-core): return the exposeProxy from mount (#4606)
This commit is contained in:
parent
2ca45dc3e6
commit
5aa4255808
@ -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'
|
import { defineComponent, h, ref } from '../src'
|
||||||
|
|
||||||
describe('api: expose', () => {
|
describe('api: expose', () => {
|
||||||
@ -170,6 +170,26 @@ describe('api: expose', () => {
|
|||||||
render(h(Parent), root)
|
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', () => {
|
test('expose should allow access to built-in instance properties', () => {
|
||||||
const GrandChild = defineComponent({
|
const GrandChild = defineComponent({
|
||||||
render() {
|
render() {
|
||||||
|
@ -3,7 +3,8 @@ import {
|
|||||||
Data,
|
Data,
|
||||||
validateComponentName,
|
validateComponentName,
|
||||||
Component,
|
Component,
|
||||||
ComponentInternalInstance
|
ComponentInternalInstance,
|
||||||
|
getExposeProxy
|
||||||
} from './component'
|
} from './component'
|
||||||
import {
|
import {
|
||||||
ComponentOptions,
|
ComponentOptions,
|
||||||
@ -309,7 +310,7 @@ export function createAppAPI<HostElement>(
|
|||||||
devtoolsInitApp(app, version)
|
devtoolsInitApp(app, version)
|
||||||
}
|
}
|
||||||
|
|
||||||
return vnode.component!.proxy
|
return getExposeProxy(vnode.component!) || vnode.component!.proxy
|
||||||
} else if (__DEV__) {
|
} else if (__DEV__) {
|
||||||
warn(
|
warn(
|
||||||
`App has already been mounted.\n` +
|
`App has already been mounted.\n` +
|
||||||
|
Loading…
x
Reference in New Issue
Block a user