-
Notifications
You must be signed in to change notification settings - Fork 144
/
18.class.html
40 lines (40 loc) · 1.04 KB
/
18.class.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
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
.red{background: red;}
.yellow{color: yellow}
.orange{color: orange}
</style>
</head>
<div id="app">
<div class="{{style}}">123</div>
//直接动态引入数据
<div v-bind:class="style">123</div>
//不是true就是false
<div v-bind:class="{'red':true,'yellow':true}">123</div>
//绑定数组
<div :class="['red','yellow']">536</div>
//三元表达式写法
<div :class="['red',flag?'orange':'yellow']">536</div>
//最简单的用法 数组和对象并用
<!--<div class='color' ng-class="{red:flag}"></div>-->
<div :class="['red',{yellow:flag},flag?'orange':'yellow']">789</div>
<!--class="{{className}}" 和v:bind:class='obj' 不要混用-->
<!--class 可以和v-bind:class共存-->
</div>
<body>
<script src="vue.js"></script>
<script>
var vm = new Vue({
el:'#app',
data:{
style:'red',
flag:true
}
});
</script>
</body>
</html>