uniapp 使用uview plus的 u-list 并排显示两列

我在开发项目时需要效果如下:一排显示两个内容

 

 

1. 思考使用技术

该项目要求是,在微信小程序上运行,scroll-view有性能问题,对于大量数据的渲染效果太差,最后我选择了 uview plsu 里面的u-list组件(该组件背后也依赖scrollview,这就无奈了,既然它说是高性能组件,我暂且相信吧

2. 实现思路

核心:

第一,给父元素设置flex布局,支持换行,横向排列

第二,子元素设置最小宽度,让它们可以互相拥挤,挤到下一行。

3. 具体代码如下

<template>
	<!-- 使用uview-plus -->
	<view>
		<u-list @scrolltolower="scrolltolower" :height="listHeight">
			<u-list-item class="glodYBox">
				<u-list-item class="setListItem" v-for="(item, index) in goodsList" :key="index">
					<view class="itemBox">
						<view>
							<image class="itemImg" :src="item"></image>
						</view>
						<text class="introduce">天锁你洛克手表鉴定案例哈哈哈</text>
						<view class="guanFang">
							<text class="guanText">¥2000</text>
							<text class="time">¥10000</text>
						</view>
					</view>
				</u-list-item>
			</u-list-item>
		</u-list>
	</view>
</template>
<script setup>
    import { onMounted,reactive,ref } from "vue";
	let listHeight = ref(0);            //列表高度
    let goodsList = reactive([]);       //商品数据

    onMounted(()=>{
		//1. 请求手表箱包 或 珠宝配饰 或 手机数码 数据
		getGoodsList();
		//2.(1)获取windowHeight(2)减去上面高度175 和 底部tab高度50(3)将rpx转化成px
		setListHeight();
	});

    const getGoodsList = ()=>{
        let arr  = [
			"/static/goldEye/gold7.jpg",
			"/static/goldEye/gold8.jpg",
			"/static/goldEye/gold9.jpg",
			"/static/goldEye/gold10.jpg",
			"/static/goldEye/gold11.jpg",
			"/static/goldEye/gold12.jpg"
		];
		goodsList.push(...arr);
    };

    const setListHeight = ()=>{
		let tempHeight = uni.getSystemInfoSync().windowHeight;
		let tempHeightRpx= tempHeight*2-175-50;
		listHeight.value = parseInt(tempHeightRpx/2);
	};
</script>


<style lang="less" scoped>
	.glodYBox{
		display: flex;
		flex-direction: row;
		flex-wrap: wrap;
		justify-content: space-between;
		.setListItem{
			flex: 0;
			.itemBox {
				width: 330rpx;
				min-width: 330rpx;
				overflow: hidden;
				margin: 10rpx 0;
			
				.introduce {
					font-size: 28rpx;
				}
			
				.guanFang {
					display: flex;
					flex-direction: row;
					justify-content: flex-start;
					align-items: center;
			
					.guanText {
						font-size: 18rpx;
						color: #555;
						margin-right: 10rpx;
					}
					.time {
						font-size: 18rpx;
						color: #ccc;
						text-decoration: line-through;
					}
				}
			}	
		}
	}

	.itemImg {
		width: 330rpx;
		height: 400rpx;
		border-radius: 10rpx;
	}
</style>

 

4. 到此就会暴漏该组件的问题,它在微信开发者工具里居然是纵向的,而在chrome浏览器是正常的一排两列显示的。

 具体原因因为该组件,在微信小程序端,多添加了一个view,并设置了默认属性

我下面图的箭头指向,那个u-list-item 就是后插入的view添加的class 

我根据显示的样式路径(uni_modules/uview-plus/components/u-list-item/u-list-item.vue),找到源码u-list-item这类,之后修改为如下

.u-list-item {
		flex-direction: row;
		flex-shrink: 1;
		flex-wrap: wrap;
		justify-content: space-between;
	}

 

 

  • 3
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

tengyuxin

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值