File tree Expand file tree Collapse file tree 2 files changed +48
-1
lines changed Expand file tree Collapse file tree 2 files changed +48
-1
lines changed Original file line number Diff line number Diff line change @@ -35,6 +35,9 @@ export function mixin(Vue: VueConstructor) {
35
35
} ,
36
36
updated ( this : ComponentInstance ) {
37
37
updateTemplateRef ( this )
38
+ if ( this . $vnode ?. context ) {
39
+ updateTemplateRef ( this . $vnode . context )
40
+ }
38
41
} ,
39
42
} )
40
43
Original file line number Diff line number Diff line change 1
1
const Vue = require ( 'vue/dist/vue.common.js' )
2
- const { ref, watchEffect } = require ( '../src' )
2
+ const { ref, watchEffect, nextTick } = require ( '../src' )
3
3
4
4
describe ( 'ref' , ( ) => {
5
5
it ( 'should work' , ( done ) => {
@@ -69,6 +69,50 @@ describe('ref', () => {
69
69
. then ( done )
70
70
} )
71
71
72
+ // #296
73
+ it ( 'should dynamically update refs in context' , async ( ) => {
74
+ const vm = new Vue ( {
75
+ setup ( ) {
76
+ const barRef = ref ( null )
77
+ return {
78
+ barRef,
79
+ }
80
+ } ,
81
+ template : `<div>
82
+ <foo><bar ref="barRef"/></foo>
83
+ </div>` ,
84
+ components : {
85
+ bar : {
86
+ setup ( ) {
87
+ const name = ref ( 'bar' )
88
+ return {
89
+ name,
90
+ }
91
+ } ,
92
+ template : '<div> {{name}} </div>' ,
93
+ } ,
94
+ foo : {
95
+ setup ( ) {
96
+ const showSlot = ref ( false )
97
+ const setShow = ( ) => {
98
+ showSlot . value = true
99
+ }
100
+ return {
101
+ setShow,
102
+ showSlot,
103
+ }
104
+ } ,
105
+ template : `<div> <slot v-if="showSlot"></slot> </div>` ,
106
+ } ,
107
+ } ,
108
+ } ) . $mount ( )
109
+ await nextTick ( )
110
+ //@ts -ignore
111
+ vm . $children [ 0 ] . setShow ( )
112
+ await nextTick ( )
113
+ //@ts -ignore
114
+ expect ( vm . $refs . barRef ) . toBe ( vm . barRef )
115
+ } )
72
116
// TODO: how ?
73
117
// it('work with createElement', () => {
74
118
// let root;
You can’t perform that action at this time.
0 commit comments