File tree Expand file tree Collapse file tree 2 files changed +28
-7
lines changed Expand file tree Collapse file tree 2 files changed +28
-7
lines changed Original file line number Diff line number Diff line change 8
8
.orange {
9
9
color : orange;
10
10
}
11
+ .static {
12
+ font-weight : bold;
13
+ }
11
14
[v-cloak ] {
12
15
opacity : 0 ;
13
16
}
17
20
import { createApp , reactive } from '../src'
18
21
19
22
// for testing
20
- const data = window . data = reactive ( {
23
+ const data = ( window . data = reactive ( {
21
24
id : 'green' ,
22
25
classes : [ 'foo' , { red : true } ] ,
23
26
style : { color : 'blue' } ,
24
27
obj : {
25
28
class : 'orange'
26
29
}
27
- } )
30
+ } ) )
28
31
29
32
createApp ( data ) . mount ( )
30
33
</ script >
31
34
32
35
< div v-scope v-cloak >
33
36
< div :id ="id "> simple binding - this should be green</ div >
34
- < div :class ="classes "> class binding - this should be red</ div >
35
- < div :style ="style "> style binding - this should be blue</ div >
37
+ < div class ="static " :class ="classes ">
38
+ class binding - this should be red and bold
39
+ </ div >
40
+ < div style ="font-weight: bold " :style ="style ">
41
+ style binding - this should be blue and bold
42
+ </ div >
36
43
< div v-bind ="obj "> object binding - this should be orange</ div >
37
44
</ div >
Original file line number Diff line number Diff line change @@ -10,14 +10,20 @@ import {
10
10
11
11
const forceAttrRE = / ^ ( s p e l l c h e c k | d r a g g a b l e | f o r m | l i s t | t y p e ) $ /
12
12
13
- export const bind : Directive < Element > = ( {
13
+ export const bind : Directive < Element & { _class ?: string } > = ( {
14
14
el,
15
15
get,
16
16
effect,
17
17
arg,
18
18
modifiers
19
19
} ) => {
20
20
let prevValue : any
21
+
22
+ // record static class
23
+ if ( arg === 'class' ) {
24
+ el . _class = el . className
25
+ }
26
+
21
27
effect ( ( ) => {
22
28
let value = get ( )
23
29
if ( arg ) {
@@ -39,9 +45,17 @@ export const bind: Directive<Element> = ({
39
45
} )
40
46
}
41
47
42
- function setProp ( el : Element , key : string , value : any , prevValue ?: any ) {
48
+ function setProp (
49
+ el : Element & { _class ?: string } ,
50
+ key : string ,
51
+ value : any ,
52
+ prevValue ?: any
53
+ ) {
43
54
if ( key === 'class' ) {
44
- el . setAttribute ( 'class' , normalizeClass ( value ) || '' )
55
+ el . setAttribute (
56
+ 'class' ,
57
+ normalizeClass ( el . _class ? [ el . _class , value ] : value ) || ''
58
+ )
45
59
} else if ( key === 'style' ) {
46
60
value = normalizeStyle ( value )
47
61
const { style } = el as HTMLElement
You can’t perform that action at this time.
0 commit comments