-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path15.Binding Inline Styles.html
58 lines (50 loc) · 1.16 KB
/
15.Binding Inline Styles.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<!--
v-bind:style
-->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Binding Inline Styles </title>
<script type="text/javascript"src="vue.js"></script>
</head>
<body>
Obejct Syntax
<div id="A" v-bind:style="{ color: activeColor, fontSize: fontSize + 'px' }"> "A" </div>
<div id="B" v-bind:style="styleObject"> "B" </div>
<!-- A和B是等价的,都会编译成 <div class="active text-danger"></div> -->
Array Syntax
<div id="C" v-bind:style="[baseStyles, overridingStyles]"> "C" </div>
</body>
<script type="text/javascript">
var vm = new Vue({
el:"#A",
data: {
activeColor: 'red',
fontSize: 30
}
});
var vm = new Vue({
el:"#B",
data: {
styleObject: {
color: 'blue',
fontSize: '50px'
}
}
});
var vm = new Vue({
el:"#C",
data: {
baseStyles: {
color: 'green',
fontSize: '70px'
},
overridingStyles:{
border:'solid 2px green',
width:'120px'
}
}
});
</script>
</html>