File tree Expand file tree Collapse file tree 2 files changed +28
-2
lines changed
src/core/instance/render-helpers
test/unit/features/directives Expand file tree Collapse file tree 2 files changed +28
-2
lines changed Original file line number Diff line number Diff line change @@ -22,14 +22,17 @@ export function bindObjectProps (
2222 if ( Array . isArray ( value ) ) {
2323 value = toObject ( value )
2424 }
25+ let hash
2526 for ( const key in value ) {
2627 if ( key === 'class' || key === 'style' ) {
27- data [ key ] = value [ key ]
28+ hash = data
2829 } else {
2930 const type = data . attrs && data . attrs . type
30- const hash = asProp || config . mustUseProp ( tag , type , key )
31+ hash = asProp || config . mustUseProp ( tag , type , key )
3132 ? data . domProps || ( data . domProps = { } )
3233 : data . attrs || ( data . attrs = { } )
34+ }
35+ if ( ! ( key in hash ) ) {
3336 hash [ key ] = value [ key ]
3437 }
3538 }
Original file line number Diff line number Diff line change @@ -166,6 +166,29 @@ describe('Directive v-bind', () => {
166166 } ) . then ( done )
167167 } )
168168
169+ it ( 'bind object with overwrite' , done => {
170+ const vm = new Vue ( {
171+ template : '<input v-bind="test" id="foo" :class="test.value">' ,
172+ data : {
173+ test : {
174+ id : 'test' ,
175+ class : 'ok' ,
176+ value : 'hello'
177+ }
178+ }
179+ } ) . $mount ( )
180+ expect ( vm . $el . getAttribute ( 'id' ) ) . toBe ( 'foo' )
181+ expect ( vm . $el . getAttribute ( 'class' ) ) . toBe ( 'hello' )
182+ expect ( vm . $el . value ) . toBe ( 'hello' )
183+ vm . test . id = 'hi'
184+ vm . test . value = 'bye'
185+ waitForUpdate ( ( ) => {
186+ expect ( vm . $el . getAttribute ( 'id' ) ) . toBe ( 'foo' )
187+ expect ( vm . $el . getAttribute ( 'class' ) ) . toBe ( 'bye' )
188+ expect ( vm . $el . value ) . toBe ( 'bye' )
189+ } ) . then ( done )
190+ } )
191+
169192 it ( 'bind object with class/style' , done => {
170193 const vm = new Vue ( {
171194 template : '<input class="a" style="color:red" v-bind="test">' ,
You can’t perform that action at this time.
0 commit comments