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

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

交互功能扩展

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

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

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

uniapp商品列表

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

相关文章

vue实现列表循环

vue实现列表循环

列表循环的实现方式 在Vue中实现列表循环主要依赖于v-for指令,该指令基于源数据多次渲染元素或模板块。 基础数组循环 使用v-for遍历数组时,语法为item in items或(item,…

vue 实现列表多选

vue 实现列表多选

Vue 实现列表多选的方法 使用 v-model 绑定数组 通过 v-model 绑定一个数组,可以自动处理多选逻辑。适用于复选框(checkbox)场景。 <template> &…

vue实现影片列表

vue实现影片列表

Vue 实现影片列表 使用 Vue CLI 创建项目 确保已安装 Vue CLI,通过以下命令创建新项目: vue create movie-list cd movie-list 安装依赖 根…

vue实现列表组件

vue实现列表组件

Vue 列表组件实现方法 基础列表渲染 使用 v-for 指令渲染数组数据,需配合 :key 提升性能: <template> <ul> <li v-for…

vue实现虚拟列表

vue实现虚拟列表

虚拟列表的概念 虚拟列表(Virtual List)是一种优化长列表渲染性能的技术,通过仅渲染可视区域内的元素,减少DOM节点数量,从而提升页面性能。适用于数据量大的场景(如表格、下拉选择器等)。…

vue实现卡片列表

vue实现卡片列表

Vue 实现卡片列表 使用 v-for 动态渲染卡片列表 通过 Vue 的 v-for 指令可以动态渲染卡片列表,数据通常存储在组件的 data 或通过 API 获取。 <template&…