fix(runtime-core): align $parent/$root with the template ref when using expose (#3158)

This commit is contained in:
HcySunYang
2021-02-07 21:39:52 +08:00
committed by GitHub
parent 3efa2aff13
commit f43a3b0beb
3 changed files with 45 additions and 6 deletions

View File

@@ -141,4 +141,32 @@ describe('api: expose', () => {
expect(childRef.value).toBeTruthy()
expect(childRef.value.foo).toBe(1)
})
test('with $parent/$root', () => {
const Child = defineComponent({
render() {
expect((this.$parent! as any).foo).toBe(1)
expect((this.$parent! as any).bar).toBe(undefined)
expect((this.$root! as any).foo).toBe(1)
expect((this.$root! as any).bar).toBe(undefined)
}
})
const Parent = defineComponent({
expose: [],
setup(_, { expose }) {
expose({
foo: 1
})
return {
bar: 2
}
},
render() {
return h(Child)
}
})
const root = nodeOps.createElement('div')
render(h(Parent), root)
})
})