uniapp商品列表
商品列表实现方法
在uniapp中实现商品列表功能,可以通过多种方式完成,以下是几种常见的方法:
使用scroll-view组件实现滚动列表
<scroll-view scroll-y="true" style="height: 100vh;">
<view v-for="(item, index) in goodsList" :key="index" class="goods-item">
<image :src="item.image" mode="aspectFill"></image>
<text>{{item.title}}</text>
<text>¥{{item.price}}</text>
</view>
</scroll-view>
使用mescroll-uni实现上拉加载下拉刷新 安装mescroll-uni插件后,可以轻松实现分页加载功能:

<mescroll-uni ref="mescrollRef" @init="mescrollInit" @down="downCallback" @up="upCallback">
<view v-for="(item, index) in goodsList" :key="index">
<!-- 商品项内容 -->
</view>
</mescroll-uni>
通过uni-list组件实现标准列表 uni-list提供了标准化的列表样式:
<uni-list>
<uni-list-item v-for="(item, index) in goodsList" :key="index"
:title="item.title"
:note="'¥'+item.price"
:thumb="item.image"
clickable
@click="gotoDetail(item.id)">
</uni-list-item>
</uni-list>
数据获取与处理
商品列表通常需要从后端API获取数据:

export default {
data() {
return {
goodsList: [],
page: 1,
pageSize: 10
}
},
methods: {
async fetchGoodsList() {
const res = await uni.request({
url: 'https://api.example.com/goods',
data: {
page: this.page,
pageSize: this.pageSize
}
})
this.goodsList = res.data.list
}
},
onLoad() {
this.fetchGoodsList()
}
}
样式优化建议
商品列表的视觉呈现很重要,可以考虑以下样式优化:
.goods-item {
display: flex;
padding: 20rpx;
border-bottom: 1rpx solid #eee;
}
.goods-item image {
width: 200rpx;
height: 200rpx;
margin-right: 20rpx;
}
.goods-item text {
display: block;
}
.price {
color: #f40;
font-weight: bold;
}
性能优化技巧
长列表性能优化是关键:
- 使用虚拟列表技术(virtual-list)处理大量数据
- 图片懒加载:
<image lazy-load> - 分页加载数据,避免一次性请求过多
- 合理使用
v-if和v-show控制元素渲染
交互功能扩展
商品列表通常需要添加以下交互功能:
- 收藏按钮
- 加入购物车按钮
- 商品筛选和排序功能
- 搜索功能集成
- 分类导航联动
通过以上方法,可以在uniapp中实现功能完善、性能优良的商品列表页面。






