属性绑定Class和Style
绑定Class
1.通过数组的方式来实现
2.通过对象的方式来实现
!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Vue模板语法</title>
<style>
.title{
font-size: 20px;
color: red;
}
.main-title{
font-weight: 800;
}
</style>
</head>
<body>
<p class="title">中国,加油</p>
<div id="app">
<!-- <p v-bind:class="[class1,class2]">中国,加油!!!</p> -->
<!-- <p v-bind:class="[class1]">中国,加油!!!</p> -->
<!-- <p v-bind:class="{title:class1,'main-title':class2}">hello world</p> -->
<!-- <p v-bind:style="{'background-color':background}">教育</p> -->
<!-- <p v-bind:style="{backgroundColor:background}">教育</p> -->
<!-- <p :style="pstyle">教育</p> -->
<p v-bind:style="[pclass1,pclass2]">什么时候好起来</p>
</div>
</body>
</html>
<script src="./vue.js"></script>
<script>
new Vue({
el: "#app",
data: {
class1:"title main-title",
// class2:"main-title"
class1:true,
class2:true,
background: 'red',
pstyle:{
backgroundColor:'red',
'font-size':'20px'
},
pclass1:{
backgroundColor:'rgb(255,255,51)',
fontSize: '22px'
},
pclass2:{
'font-weight':'800',
}
}
})
</script>