小程序-wx:if跟hidden

本文探讨了在微信小程序中wx:if与hidden指令的区别,特别是在元素为flex布局时hidden可能遇到的问题。建议避免在使用hidden时应用flex布局。

wx:if跟hidden都是控制显示隐藏;具体区别,用谁更合适 官方文档

主要说使用hidden,在项目中发现hidden有的时候使用起来,挂了,不起效果,后来查了下,发现是元素不是block布局,使用了flex!不要使用flex就可以了!

<view class="content-item-info"> <view class="content-item-text-name"> <view class="content-item-text-names">{{item.name}}</view> <view class="content-item-text-id">({{item.no}})</view> </view> <text class="content-item-text-tag" wx:for="{{item.positions}}" wx:for-item='position' wx:key="index" wx:if="{{index === 0}}">{{position.name}}<text wx:if="{{item.positions.length > 1}}">...</text></text> <view wx:if="{{item.verified == 2 || item.verified == '2'}}" class="status-tag status-verified">{{verifiedDict[item.verified]}}</view> <view wx:elif="{{item.verified == 7 || item.verified == '7'}}" class="status-tag status-graduated">{{verifiedDict[item.verified]}}</view> <view wx:else class="status-tag status-other">{{verifiedDict[item.verified]}}</view> </view>.content-item { background: #fff; border-top-style: solid; border-bottom-style: solid; border-width: 8rpx; border-color: #f2f2f2; height: 150rpx; display: flex; align-items: center; /* justify-content: space-between; */ } .content-item-text { width: calc(100% - 80rpx); padding-left: 20rpx; padding-right: 20rpx; } .content-item-info { display: flex; align-items: center; margin-bottom: 10rpx; } .content-item-img { height: 80rpx; width: 80rpx; margin-left: 30rpx; border-radius: 50%; /* 使图片变为圆形 */ overflow: hidden; /* 确保图片不会超出容器 */ } .content-item-text-name { /* display: block; */ font-size: 30rpx; font-weight: bold; color: rgba(0, 0, 0, 0.65); } content-item-text-names { float: left; } content-item-text-id { float: left; } .content-item-text-tag { display: block; font-size: 24rpx; color: #3391f5; padding: 4rpx 16rpx; margin-left: 14rpx; background: #c6e2ff; } .status-tag { margin-left: auto; font-size: 24rpx; padding: 4rpx 15rpx; border-radius: 20rpx; color: #4ea5ff; } .status-verified { background-color: #ecf5ff; } .status-graduated { background-color: #fdf6ec; color:#ecb66f; } .status-other { /* background-color: #c3cbd3; */ background-color: #f4f4f5; color:#909399; } .content-item-text-class { font-size: 26rpx; color: rgba(0, 0, 0, 0.45); }我现在改成这样了左边姓名学号列的分成两个盒子放在一个盒子里去了,我现在想要名字短的话就让名字和学号一行显示,像我图片第一个用户就是名字长了,就想现在这样姓名和学号换行显示
12-11
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值