vue.js从入门到深入再到随心而用———vue中的class样式

vue中的class样式

1.4中写法

  1. :class="[‘xxx’,‘xxx’]"
  2. :class="[‘xxxx’,‘xxxxx’,flag?‘xxxx’:’’]"
  3. :class="[‘xxx’,‘xxxx’,{‘xxxx’:flag}]"
  4. :class="{red:false,thin:true,active:true}"也可以这样写:class=“classobj”,然后把
    classobj:{red:false,thin:true,active:true}写在vue中

2.代码

<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
		<style type="text/css">
			.red{
				color: red;
			}
			.thin{
				font-weight: 200;
			}
			.italic{
				font-style: italic;
			}
			.active{
				letter-spacing: 0.5em;
			}
		</style>
		<script type="text/javascript" src="../js/vue.min.js" ></script>
	</head>
	<body>
		<div id="app">
			<!--第一种使用方式,注意:这里的class需要使用v-bind做数据绑定-->
			<!--<h1 :class="['red','thin']">这是一很大的h1</h1>-->
			
			<!--在数据中使用三元表达式-->
			<!--<h1 :class="['italic','thin',flag?'active':'']">这是一很大的h1</h1>-->
			
			<!--在数组中使用对象代替三元表达式,提高代码啊可读性-->
			<!--<h1 :class="['red','thin',{'active':flag}]">这是一很大的h1</h1>-->
			
			<!--在为class使用v-bind绑定对象的时候,对象的属性是类名,由于对象的属性可带引号,也可不带引号,所以没写引号
				属性的值是一个标识符
			-->
			<h1 :class="{red:false,thin:true,active:true}">这是一很大的h1</h1>
			<h1 :class="classobj">这是一很大的h1</h1>
		</div>
		<script type="text/javascript">
			
		new Vue({
			el:'#app',
			data:{
				flag:true,
				classobj:{red:true,thin:true,active:true}
			},
			methods:{
				
			}
		})
		</script>

	</body>
</html>

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值