vue.js class的妙用 上

<!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>	

解释:

在这里插入图片描述
在这里插入图片描述
主要在于理解这两段代码。
第两段代码的意思是

<div class='red'></div>

效果:

在这里插入图片描述

<!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>

效果:

在这里插入图片描述

解释:

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/qq_37805832/article/details/113824550