File tree Expand file tree Collapse file tree 3 files changed +35
-4
lines changed
test/unit/features/directives Expand file tree Collapse file tree 3 files changed +35
-4
lines changed Original file line number Diff line number Diff line change @@ -53,6 +53,7 @@ declare interface VNodeData {
53
53
} ;
54
54
directives ?: Array < VNodeDirective > ;
55
55
keepAlive ?: boolean ;
56
+ [ key : string ] : any ;
56
57
}
57
58
58
59
declare type VNodeDirective = {
Original file line number Diff line number Diff line change @@ -165,10 +165,14 @@ export function renderMixin (Vue: Class<Component>) {
165
165
}
166
166
const data = vnode . data
167
167
for ( const key in value ) {
168
- const hash = asProp || config . mustUseProp ( key )
169
- ? data . domProps || ( data . domProps = { } )
170
- : data . attrs || ( data . attrs = { } )
171
- hash [ key ] = value [ key ]
168
+ if ( key === 'class' || key === 'style' ) {
169
+ data [ key ] = value [ key ]
170
+ } else {
171
+ const hash = asProp || config . mustUseProp ( key )
172
+ ? data . domProps || ( data . domProps = { } )
173
+ : data . attrs || ( data . attrs = { } )
174
+ hash [ key ] = value [ key ]
175
+ }
172
176
}
173
177
}
174
178
}
Original file line number Diff line number Diff line change @@ -144,6 +144,32 @@ describe('Directive v-bind', () => {
144
144
} ) . then ( done )
145
145
} )
146
146
147
+ it ( 'bind object with class/style' , done => {
148
+ const vm = new Vue ( {
149
+ template : '<input class="a" style="color:red" v-bind="test">' ,
150
+ data : {
151
+ test : {
152
+ id : 'test' ,
153
+ class : [ 'b' , 'c' ] ,
154
+ style : { fontSize : '12px' }
155
+ }
156
+ }
157
+ } ) . $mount ( )
158
+ expect ( vm . $el . id ) . toBe ( 'test' )
159
+ expect ( vm . $el . className ) . toBe ( 'a b c' )
160
+ expect ( vm . $el . style . color ) . toBe ( 'red' )
161
+ expect ( vm . $el . style . fontSize ) . toBe ( '12px' )
162
+ vm . test . id = 'hi'
163
+ vm . test . class = [ 'd' ]
164
+ vm . test . style = { fontSize : '14px' }
165
+ waitForUpdate ( ( ) => {
166
+ expect ( vm . $el . id ) . toBe ( 'hi' )
167
+ expect ( vm . $el . className ) . toBe ( 'a d' )
168
+ expect ( vm . $el . style . color ) . toBe ( 'red' )
169
+ expect ( vm . $el . style . fontSize ) . toBe ( '14px' )
170
+ } ) . then ( done )
171
+ } )
172
+
147
173
it ( 'bind object as prop' , done => {
148
174
const vm = new Vue ( {
149
175
template : '<input v-bind.prop="test">' ,
You can’t perform that action at this time.
0 commit comments