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 (
22
22
if ( Array . isArray ( value ) ) {
23
23
value = toObject ( value )
24
24
}
25
+ let hash
25
26
for ( const key in value ) {
26
27
if ( key === 'class' || key === 'style' ) {
27
- data [ key ] = value [ key ]
28
+ hash = data
28
29
} else {
29
30
const type = data . attrs && data . attrs . type
30
- const hash = asProp || config . mustUseProp ( tag , type , key )
31
+ hash = asProp || config . mustUseProp ( tag , type , key )
31
32
? data . domProps || ( data . domProps = { } )
32
33
: data . attrs || ( data . attrs = { } )
34
+ }
35
+ if ( ! ( key in hash ) ) {
33
36
hash [ key ] = value [ key ]
34
37
}
35
38
}
Original file line number Diff line number Diff line change @@ -166,6 +166,29 @@ describe('Directive v-bind', () => {
166
166
} ) . then ( done )
167
167
} )
168
168
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
+
169
192
it ( 'bind object with class/style' , done => {
170
193
const vm = new Vue ( {
171
194
template : '<input class="a" style="color:red" v-bind="test">' ,
You can’t perform that action at this time.
0 commit comments