vue.js class的妙用 上

2021-03-02 15:44:28 浏览数 (1)

代码语言:javascript复制
<!DOCTYPE html>
<html lang="zh">
<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"><script type="text/javascript" src='vue.min.js'></script>
	<title></title><script type="text/javascript"></script>
	<style type="text/css">
		body{background: #ccc;}
		div{width: 100px;height: 100px;}
		.red{background: red;}
	</style>
</head>
<body>
	<input type="button" value='changed'>
	<div class="{{myDiv}}"></div>
	<script type="text/javascript">
		new Vue({
			el:'body',
			data:{
				myDiv:'red'
			},
			methods:{
				
			}
		});
	</script>
</body>
</html>	

解释:

主要在于理解这两段代码。 第两段代码的意思是

代码语言:javascript复制
<div class='red'></div>

效果:

代码语言:javascript复制
<!DOCTYPE html>
<html lang="zh">
<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">
	<script type="text/javascript" src='vue.min.js'></script>
	<title></title>
	<style type="text/css">
		body{background: #ccc;}
		div{width: 100px;height: 100px;}
		.red{background: red;}
	</style>
</head>
<body>
	
	<input type="button" value='changed'>
	<div v-bind:class='myDiv'></div>
	<script type="text/javascript">
	
	
	new Vue({
		el:'body',
		data:{
			myDiv:'red',
		},
		methods:{
			
		}
	})
	
	
	
	</script>
</body>
</html>

效果:

解释:

0 人点赞