Vue-样式绑定

1.对class属性进行绑定

<style>
		.app {
			width: 200px;
			height: 200px;
			background-color: purple;
		}
		.app1 {
			width: 100px;
			height: 100px;
			background-color: aqua;
		}
	</style>
	<body>
		<div class="app" :class="data1">
			<button @click="fn">切换模式</button>
		</div>
	</body>
	<script>
		new Vue({
			el:".app",
			data:{
				data1:"app",
				flag:true
			},
			methods:{
				fn(){
					this.flag=!this.flag
					if(this.flag==true){
						this.data1="app"
					}else{
						this.data1="app1"
					}
				}
			}
		})
	</script>

2.对style属性的绑定

<body>
		<div id="app">
			<button @click="fn">切换</button>
			<div :style='{color:color,fontSize:fontsize,backgroundColor:n,width:"200px",height:"200px"}'>放学咯!!!!</div>
		</div>
	</body>
	<script>
		new Vue({
			el:"#app",
			data:{
				color:"red",
				fontsize:"20px",
				flag:true,
				n:"purple"
			},
			methods:{
				fn(){
					this.flag=!this.flag
					if(this.flag==true){
						this.color="red"
						this.fontsize="14px"
						this.n="purple"
					}else{
						this.color="blue"
						this.fontsize="20px"
						this.n="green"
					}
				}
			}
		})
	</script>

  

相关文章

可以通过min-width属性来设置el-table-column的最小宽度。以...
yarn dev,当文件变动后,会自动重启。 yanr start不会自动重...
ref 用于创建一个对值的响应式引用。这个值可以是原始值(如...
通过修改 getWK005 函数来实现这一点。这里的 query 参数就是...
&lt;el-form-item label=&quot;入库类型&quot; ...
API 变动 样式类名变化: 一些组件的样式类名有所变动,可能需...