动态绑定class和style

###vue动态绑定class和style

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

<!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="https://cdn.bootcss.com/vue/2.4.2/vue.min.js"></script>
<style>
.cont{width: 100px;height: 100px;border: 1px solid #ccc;}
.pcont{border: 1px solid red;}
</style>
</head>
<body>
<div id="app">
<div :class="{'cont':contt}"></div>
<p v-text='name' :class="{'pcont':contt}"></p>
</div>
<script>
// 绑定class 分为两种 1.对象语法 2.数组语法
//同理绑定内联样式 :style
let vm=new Vue({
el:"#app",
data:{
contt:true,
name:'nihao'

}
})
</script>
</body>
</html>