uniapp在:style动态设置样式

该博客介绍了如何在Vue.js中利用动态样式和v-for指令实现组件间的交互。通过示例代码展示了如何根据条件改变元素背景色、过渡效果以及设置z-index,同时结合触摸事件处理函数实现触摸操作。内容着重于前端开发中的动态样式控制和列表渲染。
:style="{'text-align': 'center','margin-bottom': '20rpx','padding-top':padding_top}"

:style="{backgroundColor:`${query.label.color}`}"

v-for遍历写法

<template>
	<view class="app-movable-area" :style="[containerSize]">
		<template v-if="controlsPositionArray.length !== 0">
			<view v-for="(item, index) in controlsArray" :key="index" class="_item"
				:style="{'background': item, 'transition': (curretnControlsIndex === index ? 'initial' : '.3s'), 'z-index': (curretnControlsIndex === index ? 1 : 0), 'width': controlsSize.width + 'px', 'height': controlsSize.height + 'px', 'top': controlsPositionArray[index].top + 'px',  'left': controlsPositionArray[index].left + 'px'}">
				<view @touchstart="handleTouchstart($event, index)" @touchmove="handleTouchmove" @touchend="handleTouchend" :style="{'background': item}" style="width: 100%; height: 100%;">
					<!-- 自定义内容 -->
					<view style="display: flex; align-items: center; justify-content: center; width: 100%; height: 100%;">
						{{index + 1}}
					</view>
				</view>
			</view>
		</template>
	</view>
</template>

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值