zl程序教程

您现在的位置是:首页 >  前端

当前栏目

Vue:class和style绑定

Vue 绑定 Class Style
2023-09-27 14:22:47 时间
<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<meta name="author" content="xiaonaihu" />
		<meta name="generator" content="HBuilder X" />
		<title>class和style绑定</title>
		<script src="../../lib/vue.js"></script>
	</head>
	<body>
		<div id="app">
			<div
			class="text"
			v-bind:class = "[isActive?'active':'',isGreen?'green':'']"
			style="width: 200px; height: 200px; text-align: center; line-height: 200px;">
				hi vue
			</div>
			<div
				:style ="{
					color:color,
					fontSize:size,
					background:isRed?'#ff0000':''}">
				hi vue
			</div>
		</div>
		<script type="text/javascript">
			var vm = new Vue({
				el:"#app",
				data:{
					isActive:true,
					isGreen:true,
					isRed:true,
					size:'50px'
				}
			});
		</script>
		<style>
			.test{
				font-size: 30px;
			}
			.green{
				color: #00ff00;
			}
			.active{
				background: #ff0000;
			}
		</style>
	</body>
</html>