Fork me on GitHub

vue的class对象绑定

本节课程:

v-bind:class

v-bind:class

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
下面我们对html进行了class的绑定

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>vueDemo</title>
<script src="https://cdn.jsdelivr.net/npm/vue"></script>
</head>
<style>
.active
{
color: red;
}
.big
{
font-weight: bolder;
font-size: 64px;
}

</style>
<body>
<div id="myApp">
<div v-bind:class="myClass">文本</div>
<button @click="btnClick">点击改变</button>
</div>
</body>
</html>
<script >
var myApp = new Vue
({
el: "#myApp",
data:
{
myClass:
{
active:true,
big:true
}
},
methods:
{
btnClick: function()
{
this.myClass.active = !this.myClass.active;
this.myClass.big = !this.myClass.big;
}
}

})
</script>
-------------本文结束感谢您的阅读-------------