vue中样式

<!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>Title</title>
<script src="js/vue-2.4.0.js"></script>
<style>
.red{
color: red;
}
.thin{
font-weight: 200;
}
.italic{
font-style: italic;
}
.active{
letter-spacing: 0.5em;
}
</style>
</head>
<body>
<div id="app">
<!--第一种方式,直接传递一个数组,注意:这里的 class 需要使用 v-bind 做数据绑定-->
<!--<h1 :class="['red','thin']">这是个超级大的大大h1!!!</h1>-->

<!--在数组中使用三元表达式-->
<!--<h1 :class="['red','thin',flag?'italic':'']">这是个超级大的大大h1!!!</h1>-->

<!--在数组中使用 对象来代替三元表达式,提高代码的可读性-->
<!--<h1 :class="['red','thin',{'active':flag}]">这是个超级大的大大h1!!!</h1>-->

<!--在为class使用v-bind 绑定对象的时候,对象的属性是类名,由于对象的属性可带引号,
也可不带引号,所以我这里没写引号,属性的值是一个标识符-->
<h1 :class="classObj">这是个超级大的大大h1!!!</h1>
</div>
<script>
const vm=new Vue({
el:'#app',
data:{
flag:true,
classObj:{red:true,thin:false,italic:true,active:true}
},
methods:{

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

猜你喜欢

转载自www.cnblogs.com/lujieting/p/10434774.html