0
点赞
收藏
分享

微信扫一扫

VUE3与Uniapp 四 (Class变量和内联样式)

<template>
	<!-- 通过class绑定开启或关闭某个CSS -->
	<view class="box" :class="{box2:true}">box1</view>
	<view class="box" :class="{box2:isActive}">box2</view>
	
	<!-- 使用三元表达式实现开启关闭CSS的效果 -->
	<view class="box" :class="true ? 'box2' : ''">box3</view>
	
	<view :style="{width:'300px', height:300 + 'px', fontSize:size + 'px', border:'1px solid red'}">
		Hello World
	</view>
</template>

<script setup>
	import {ref} from "vue";
	
	let isActive = ref(false);
	let size = ref(60);
</script>

<style lang="scss">
	.box{
		width:300px;
		height:300px;
		background-color: red;
		margin: 10px;
	}
	
	.box2{
		background-color: green;
	}
</style>

举报

相关推荐

0 条评论