File tree 2 files changed +33
-0
lines changed
test/unit/specs/directives 2 files changed +33
-0
lines changed Original file line number Diff line number Diff line change @@ -353,6 +353,16 @@ module.exports = {
353
353
if ( needCache ) {
354
354
this . cacheVm ( raw , vm )
355
355
}
356
+ // sync back changes for $value, particularly for
357
+ // two-way bindings of primitive values
358
+ var self = this
359
+ vm . $watch ( '$value' , function ( val ) {
360
+ if ( self . converted ) {
361
+ self . rawValue [ vm . $key ] = val
362
+ } else {
363
+ self . rawValue . $set ( vm . $index , val )
364
+ }
365
+ } )
356
366
return vm
357
367
} ,
358
368
@@ -537,6 +547,8 @@ function findNextVm (vm, ref) {
537
547
*/
538
548
539
549
function objToArray ( obj ) {
550
+ // regardless of type, store the un-filtered raw value.
551
+ this . rawValue = obj
540
552
if ( ! isPlainObject ( obj ) ) {
541
553
return obj
542
554
}
Original file line number Diff line number Diff line change @@ -603,6 +603,27 @@ if (_.inBrowser) {
603
603
} , 30 )
604
604
} )
605
605
606
+ it ( 'sync $value changes back to original array/object' , function ( done ) {
607
+ var vm = new Vue ( {
608
+ el : el ,
609
+ template :
610
+ '<div v-repeat="items">{{$value}}</div>' +
611
+ '<div v-repeat="obj">{{$value}}</div>' ,
612
+ data : {
613
+ items : [ 'a' , 'b' ] ,
614
+ obj : { foo : 'a' , bar : 'b' }
615
+ }
616
+ } )
617
+ vm . _children [ 0 ] . $value = 'c'
618
+ var key = vm . _children [ 2 ] . $key
619
+ vm . _children [ 2 ] . $value = 'd'
620
+ _ . nextTick ( function ( ) {
621
+ expect ( vm . items [ 0 ] ) . toBe ( 'c' )
622
+ expect ( vm . obj [ key ] ) . toBe ( 'd' )
623
+ done ( )
624
+ } )
625
+ } )
626
+
606
627
} )
607
628
}
608
629
You can’t perform that action at this time.
0 commit comments