当前位置:首页 > uni-app

uniapp商品列表

2026-01-13 18:10:37uni-app

商品列表实现方法

在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插件后,可以轻松实现分页加载功能:

uniapp商品列表

<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获取数据:

uniapp商品列表

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-ifv-show控制元素渲染

交互功能扩展

商品列表通常需要添加以下交互功能:

  • 收藏按钮
  • 加入购物车按钮
  • 商品筛选和排序功能
  • 搜索功能集成
  • 分类导航联动

通过以上方法,可以在uniapp中实现功能完善、性能优良的商品列表页面。

标签: 商品列表
分享给朋友:

相关文章

vue实现列表循环

vue实现列表循环

Vue 列表循环的实现方法 在 Vue 中,可以通过 v-for 指令实现列表循环渲染。以下是几种常见的实现方式: 基础列表渲染 <template> <ul>…

vue 实现商品列表

vue 实现商品列表

实现商品列表的基本结构 在Vue中实现商品列表,通常需要创建一个组件来展示商品数据。可以使用v-for指令循环渲染商品列表,并通过数据绑定动态显示商品信息。 <template> &…

vue实现商品卡片

vue实现商品卡片

Vue 实现商品卡片 在 Vue 中实现商品卡片可以通过组件化的方式完成,以下是一个完整的实现方案: 商品卡片组件 <template> <div class="product…

vue实现列表动画

vue实现列表动画

Vue 列表动画的实现方法 Vue 提供了内置的过渡和动画系统,可以通过 <transition-group> 组件实现列表动画效果。以下是几种常见的实现方式: 使用 <trans…

vue实现grid图片列表

vue实现grid图片列表

实现思路 在Vue中实现Grid图片列表,通常结合CSS Grid布局或第三方组件库(如Element UI、Ant Design Vue等)。以下是两种常见实现方式。 纯CSS Grid实现 通过…

vue实现页面列表渲染

vue实现页面列表渲染

基本列表渲染 在Vue中,可以使用v-for指令实现列表渲染。基本语法是通过v-for遍历数组或对象,动态生成DOM元素。 <template> <ul> <…