当前位置:首页 > uni-app

uniapp 内容列表

2026-03-04 23:38:10uni-app

uniapp 内容列表的实现方法

uniapp 中实现内容列表通常使用 scroll-viewlist 组件,结合数据绑定和样式调整来展示内容。

使用 scroll-view 实现基础列表

<scroll-view scroll-y="true" style="height: 100vh;">
  <view v-for="(item, index) in listData" :key="index" class="list-item">
    {{ item.title }}
  </view>
</scroll-view>

数据绑定与样式示例

export default {
  data() {
    return {
      listData: [
        { title: '项目1' },
        { title: '项目2' }
      ]
    }
  }
}
.list-item {
  padding: 20rpx;
  border-bottom: 1rpx solid #eee;
}

实现下拉刷新和上拉加载

uniapp 提供 onPullDownRefreshonReachBottom 生命周期函数实现刷新和加载功能。

页面配置

{
  "enablePullDownRefresh": true,
  "onReachBottomDistance": 50
}

逻辑实现

uniapp 内容列表

export default {
  onPullDownRefresh() {
    // 刷新数据
    setTimeout(() => {
      uni.stopPullDownRefresh()
    }, 1000)
  },
  onReachBottom() {
    // 加载更多数据
  }
}

优化列表性能

对于长列表,建议使用 uni-list 组件或实现虚拟列表。

虚拟列表实现

<scroll-view 
  scroll-y 
  :scroll-top="scrollTop"
  @scroll="handleScroll">
  <view :style="{ height: totalHeight + 'px' }">
    <view 
      v-for="item in visibleData" 
      :key="item.id"
      :style="{ transform: `translateY(${item.offset}px)` }">
      {{ item.content }}
    </view>
  </view>
</scroll-view>

列表项点击事件处理

为列表项添加点击事件和动画效果提升用户体验。

点击事件示例

uniapp 内容列表

<view 
  v-for="item in listData" 
  :key="item.id"
  @click="handleItemClick(item)"
  :class="['list-item', { 'active': activeId === item.id }]">
  {{ item.title }}
</view>

动画效果实现

.list-item {
  transition: all 0.3s;
}
.list-item.active {
  background-color: #f5f5f5;
}

列表数据过滤与搜索

实现搜索功能可以结合计算属性和过滤器。

搜索功能实现

computed: {
  filteredList() {
    return this.listData.filter(item => 
      item.title.includes(this.searchText)
    )
  }
}

模板中使用

<input v-model="searchText" placeholder="搜索..." />
<view v-for="item in filteredList" :key="item.id">
  {{ item.title }}
</view>

标签: 内容列表
分享给朋友:

相关文章

vue实现内容切换

vue实现内容切换

Vue 实现内容切换的方法 在 Vue 中实现内容切换可以通过多种方式,以下是几种常见的方法: 使用 v-if 和 v-else 指令 通过条件渲染动态切换内容。v-if 和 v-else 会根据表…

weex  vue 实现列表

weex vue 实现列表

weex + Vue 实现列表的方法 使用<list>和<cell>组件 在weex中,列表通常通过<list>和<cell>组件实现。<list…

vue列表展开实现

vue列表展开实现

Vue 列表展开实现方法 使用 v-for 和 v-show 控制展开状态 通过 v-for 渲染列表项,配合 v-show 控制子内容的显示隐藏。需要为每个列表项维护一个展开状态。 <tem…

vue实现索引列表

vue实现索引列表

Vue 实现索引列表 使用第三方库(如 better-scroll 或 vue-index-list) 安装 better-scroll 或 vue-index-list 库,可以快速实现带索引的列表…

vue实现列表demo

vue实现列表demo

以下是一个基于 Vue.js 的列表实现示例,包含基础功能与关键代码解析: 基础列表渲染 <template> <div> <ul>…

vue实现模拟列表

vue实现模拟列表

使用 Vue 实现模拟列表 在 Vue 中实现模拟列表可以通过多种方式完成,常见的方法包括使用 v-for 指令动态渲染数据、结合计算属性或方法进行列表操作。以下是一个完整的实现方案: 基础列表渲染…