File tree Expand file tree Collapse file tree 2 files changed +37
-2
lines changed
test/unit/specs/directives/public/for Expand file tree Collapse file tree 2 files changed +37
-2
lines changed Original file line number Diff line number Diff line change @@ -202,8 +202,8 @@ module.exports = {
202202 var parentScope = this . _scope || this . vm
203203 var scope = Object . create ( parentScope )
204204 // ref holder for the scope
205- scope . $refs = { }
206- scope . $els = { }
205+ scope . $refs = Object . create ( parentScope . $refs )
206+ scope . $els = Object . create ( parentScope . $els )
207207 // make sure point $parent to parent scope
208208 scope . $parent = parentScope
209209 // for two-way binding on alias
Original file line number Diff line number Diff line change @@ -849,6 +849,41 @@ if (_.inBrowser) {
849849 } )
850850 } )
851851
852+ it ( 'access parent\'s $refs' , function ( ) {
853+ var vm = new Vue ( {
854+ el : document . createElement ( 'div' ) ,
855+ template : '<c1 v-ref:c1><div v-for="n in 2">{{$refs.c1.d}}</div></c1>' ,
856+ components : {
857+ c1 : {
858+ template : '<div><slot></slot></div>' ,
859+ data : function ( ) {
860+ return {
861+ d : 1
862+ }
863+ }
864+ }
865+ }
866+ } )
867+ expect ( vm . $refs . c1 instanceof Vue ) . toBe ( true )
868+ expect ( vm . $refs . c1 . $el . innerHTML ) . toContain ( '<div>1</div><div>1</div>' )
869+ } )
870+
871+ it ( 'access parent scope\'s $els' , function ( done ) {
872+ var vm = new Vue ( {
873+ el : document . createElement ( 'div' ) ,
874+ template : '<div data-d=1 v-el:a><div v-for="n in 2">{{ready ? $els.a.dataset.d : 0}}</div></div>' ,
875+ data : {
876+ ready : false
877+ }
878+ } )
879+ expect ( vm . $els . a instanceof Element ) . toBe ( true )
880+ expect ( vm . $els . a . innerHTML ) . toContain ( '<div>0</div><div>0</div>' )
881+ vm . ready = true
882+ vm . $nextTick ( function ( ) {
883+ expect ( vm . $els . a . innerHTML ) . toContain ( '<div>1</div><div>1</div>' )
884+ done ( )
885+ } )
886+ } )
852887 } )
853888}
854889
You can’t perform that action at this time.
0 commit comments