当前位置:首页 > uni-app

uniapp分页样式

2026-03-05 08:20:45uni-app

分页样式实现方法

在UniApp中实现分页样式通常涉及前端页面布局和数据分页加载逻辑。以下是常见的实现方式:

基础分页组件样式 使用<view><text>组合实现基础分页器:

<view class="pagination">
  <text @click="prevPage" :class="{disabled: currentPage === 1}">上一页</text>
  <text v-for="page in pageCount" 
        @click="goToPage(page)"
        :class="{active: currentPage === page}">
    {{page}}
  </text>
  <text @click="nextPage" :class="{disabled: currentPage === pageCount}">下一页</text>
</view>

CSS样式示例

.pagination {
  display: flex;
  justify-content: center;
  margin-top: 20px;
}
.pagination text {
  padding: 8px 12px;
  margin: 0 5px;
  border: 1px solid #ddd;
  cursor: pointer;
}
.pagination .active {
  background-color: #007AFF;
  color: white;
}
.pagination .disabled {
  color: #ccc;
  cursor: not-allowed;
}

滚动加载分页样式

对于滚动分页(无限加载)场景:

<scroll-view 
  scroll-y 
  @scrolltolower="loadMore"
  style="height: 100vh">
  <!-- 内容列表 -->
  <view v-for="item in list">{{item.name}}</view>

  <!-- 加载状态 -->
  <view v-if="loading" class="loading">加载中...</view>
  <view v-if="noMore" class="no-more">没有更多了</view>
</scroll-view>

滚动加载样式

.loading, .no-more {
  text-align: center;
  padding: 10px;
  color: #999;
}

数据加载逻辑

分页数据请求示例:

data() {
  return {
    list: [],
    currentPage: 1,
    pageSize: 10,
    total: 0,
    loading: false,
    noMore: false
  }
},
methods: {
  async fetchData() {
    if (this.loading || this.noMore) return;

    this.loading = true;
    try {
      const res = await uni.request({
        url: 'api/list',
        data: {
          page: this.currentPage,
          size: this.pageSize
        }
      });

      this.list = [...this.list, ...res.data.list];
      this.total = res.data.total;
      this.noMore = this.list.length >= this.total;
    } finally {
      this.loading = false;
    }
  },

  loadMore() {
    if (!this.noMore) {
      this.currentPage++;
      this.fetchData();
    }
  }
}

组件库分页方案

使用uni-ui组件库的分页器:

<uni-pagination 
  :total="total" 
  :current="currentPage"
  :pageSize="pageSize"
  @change="pageChange"
/>

uni-pagination参数说明

  • show-icon: 显示首页末页图标
  • prev-text: 上一页文字
  • next-text: 下一页文字
  • pageSize: 每页数量

平台差异处理

处理不同平台的分页样式差异:

uniapp分页样式

/* #ifdef H5 */
.pagination {
  padding-bottom: 20px;
}
/* #endif */

/* #ifdef MP-WEIXIN */
.pagination text {
  padding: 6px 10px;
}
/* #endif */

以上方案可根据具体项目需求进行组合或调整,实现适合不同场景的分页效果。

标签: 分页样式
分享给朋友:

相关文章

jquery 样式

jquery 样式

jQuery 样式操作 jQuery 提供了多种方法来操作 HTML 元素的样式,包括直接修改 CSS 属性、添加或移除类、获取样式值等。 修改 CSS 属性 使用 css() 方法可以直接修改元素…

vue实现接口分页

vue实现接口分页

Vue 实现接口分页的方法 在 Vue 中实现接口分页通常需要结合后端 API 和前端分页组件。以下是常见的实现方式: 使用 Element UI 的分页组件 安装 Element UI 后,可以使…

vue实现分页请求

vue实现分页请求

Vue 实现分页请求的方法 在 Vue 中实现分页请求通常需要结合前端分页组件和后端 API 的分页逻辑。以下是常见的实现方法: 分页组件与数据绑定 使用 v-pagination 或其他分页组件(…

vue实现分页打印

vue实现分页打印

实现分页打印的基本思路 在Vue中实现分页打印功能通常需要结合CSS的分页控制属性和JavaScript的打印API。核心是通过CSS的@media print媒体查询和page-break相关属性控…

前端vue实现分页

前端vue实现分页

前端Vue实现分页的方法 在Vue中实现分页功能可以通过多种方式完成,以下是常见的实现方法: 使用Element UI的分页组件 Element UI提供了现成的分页组件el-pagination,…

vue分页的实现

vue分页的实现

Vue 分页的实现方法 使用 Element UI 的分页组件 安装 Element UI: npm install element-ui 在 main.js 中引入: import Elemen…