forked from Francis0Cheng/Vue-Personal-Notes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
06.在Vue中使用样式-css.html
62 lines (52 loc) · 1.6 KB
/
06.在Vue中使用样式-css.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
59
60
61
62
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<script src="./lib/vue.js"></script>
<style>
.red{
color: red;
}
.thin{
font-weight: 200;
}
.italic{
font-style: italic;
}
.active{
letter-spacing: 0.5em;
}
</style>
</head>
<body>
<div id="app">
<h1 class="red thin"> HUGE H1 </h1>
<br><br>
第一种方式, 直接传递一个数组, 注意:这里的class需要使用 v-blind做数组绑定
<h1 :class="['thin', 'italic']">it's a Huge H1</h1>
<br><br>
在数组中使用三元表达式
<h1 :class="['thin', 'italic', flag?'active':'']">it's a Huge h1</h1>
<br><br>
在数组中使用对象来代替三元表达式, 提高代码的可读性
<h1 :class="['thin', 'italic', {'active':flag }]">it's a Huge h1</h1>
<br><br>
在为class使用v-bind绑定对象的时候,对象的属性是类名, 由于对象的属性可带引号,也可以不带引号, 所以我没有写引号, 属性的值是一个标识符
<h1 :class="{red:true, thin:true, italic:false, active:false}">it's a Huge h1</h1>
</div>
<br><br>
<script>
var vm = new Vue({
el: '#app',
data: {
flag: true
},
methods: {
},
})
</script>
</body>
</html>