实例类(class)
<style type="text/css">
.red{
color:#EE3D11;
}
.thin{
font-weight: 200;
}
.italic{
font-style: italic;
}
.active{
letter-spacing: 0.5em;
}
</style>
传递方式(注意 class属性需要v-bind:绑定)
方式一:以数组的形式
<h1 v-bind:class="['red','thin','italic','active']">这段文字是一段很大的文字</h1>
方式二:在数组中使用三元表达式
<h1 v-bind:class="['red','thin','italic',flag?'ative':'']">这段文字是一段很大的文字</h1>
方式三:在数组中内嵌对象
<h1 v-bind:class="['red','thin','italic',{'active':false}]">这段文字是一段很大的文字</h1>
方式四:直接使用对象,易读写(推荐,推荐,推荐)
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>default</title>
<script src="../js/Vue2.6.11.js" type="text/javascript" charset="utf-8"></script>
<style type="text/css">
.red{
color:#EE3D11;
}
.thin{
font-weight: 200;
}
.italic{
font-style: italic;
}
.active{
letter-spacing: 0.5em;
}
</style>
</head>
<body>
<div id="app">
<h1 v-bind:class="myclass">这段文字是一段很大的文字</h1>
</div>
<script type="text/javascript">
var vm=new Vue({
el:'#app',
data:{
flag:true,
myclass:{
red:true,
thin:false,
italic:true,
active:true
}
},
methods:{}
})
</script>
</body>
</html>