随笔 - 11,  文章 - 0,  评论 - 0,  阅读 - 21639

1、从element-ui官网复制分页代码到项目中,修改对应的分页参数为项目的真实数据,添加背景为蓝底白字样式。

<el-pagination
               @size-change="handleSizeChange"
               @current-change="handleCurrentChange"
               :current-page="page.page"
               :page-sizes="[1, 2, 3, 4]"
               :page-size="page.size"
               layout="total, sizes, prev, pager, next, jumper"
               :total="page.totalCount"
               background
               >     
</el-pagination>
<script>
    export default {
        data(){
            return {
                // 分页
                page: {
                    page: 1,
                    size: 2,
                    totalCount: 20,
                    pageCount: 10,
                },
            }
        }
    }
</script>

生成的界面如下

2、修改属性,使上一页和下一页由原来的<和>为“上一页”和“下一页”,代码如下

主要是修改属性:prev-text和next-text

<el-pagination
               @size-change="handleSizeChange"
               @current-change="handleCurrentChange"
               :current-page="page.page"
               :page-sizes="[1, 2, 3, 4]"
               :page-size="page.size"
               layout="total, sizes, prev, pager, next, jumper"
               :total="page.totalCount"
               prev-text="上一页"
               next-text="下一页"
               background
               >
</el-pagination>

生成的界面如下

3、添加首页,尾页,总页数,代码如下

操作方法:在layout中添加 slot(插槽),配置对应插槽信息。

注意:一个分页组件只能实现一个插槽功能,layout中slot值要放在合适位置

有3个功能用了3个分页组件,第一个组件实现总条数,第二个实现首页,第三个实现了尾页功能。

<div>
    <el-pagination
                   @size-change="handleSizeChange"
                   @current-change="handleCurrentChange"
                   :current-page="page.page"
                   :page-sizes="[1, 2, 3, 4]"
                   :page-size="page.size"
                   layout="total,slot, sizes"
                   :total="page.totalCount"
                   prev-text="上一页"
                   next-text="下一页"
                   background
                   >
        <span class="el-pagination__total">,共 {{ page.page }} / {{ page.pageCount }} 页</span>
    </el-pagination>
    <el-pagination
                   @size-change="handleSizeChange"
                   @current-change="handleCurrentChange"
                   :current-page="page.page"
                   :page-sizes="[1, 2, 3, 4]"
                   :page-size="page.size"
                   layout="slot, prev, pager, next"
                   :total="page.totalCount"
                   prev-text="上一页"
                   next-text="下一页"
                   background
                   >
        <button :disabled="page.page == 1" @click="show(1)" class="btn-prev">
            首页
        </button>
    </el-pagination>
    <el-pagination
                   @size-change="handleSizeChange"
                   @current-change="handleCurrentChange"
                   :current-page="page.page"
                   :page-sizes="[1, 2, 3, 4]"
                   :page-size="page.size"
                   layout="slot,jumper"
                   :total="page.totalCount"
                   prev-text="上一页"
                   next-text="下一页"
                   background
                   >
        <button
                :disabled="page.page == page.pageCount"
                @click="show(page.pageCount)"
                class="btn-prev"
                >
            尾页
        </button>
    </el-pagination>
</div>

生成的界面如下

上图的问题是分页组件换行了,可以自行设置样式来解决,也可参考下面的代码

4、添加首页,尾页,总页数,分页组件显示在一行,代码如下

操作方法:在分页组件外层包裹一个div,设置它的样式 style="display: flex"

<div style="display: flex">
    <el-pagination
                   @size-change="handleSizeChange"
                   @current-change="handleCurrentChange"
                   :current-page="page.page"
                   :page-sizes="[1, 2, 3, 4]"
                   :page-size="page.size"
                   layout="total,slot, sizes"
                   :total="page.totalCount"
                   prev-text="上一页"
                   next-text="下一页"
                   background
                   >
        <span class="el-pagination__total">,共 {{ page.page }} / {{ page.pageCount }} 页</span>
    </el-pagination>
    <el-pagination
                   @size-change="handleSizeChange"
                   @current-change="handleCurrentChange"
                   :current-page="page.page"
                   :page-sizes="[1, 2, 3, 4]"
                   :page-size="page.size"
                   layout="slot, prev, pager, next"
                   :total="page.totalCount"
                   prev-text="上一页"
                   next-text="下一页"
                   background
                   >
        <button :disabled="page.page == 1" @click="show(1)" class="btn-prev">
            首页
        </button>
    </el-pagination>
    <el-pagination
                   @size-change="handleSizeChange"
                   @current-change="handleCurrentChange"
                   :current-page="page.page"
                   :page-sizes="[1, 2, 3, 4]"
                   :page-size="page.size"
                   layout="slot,jumper"
                   :total="page.totalCount"
                   prev-text="上一页"
                   next-text="下一页"
                   background
                   >
        <button
                :disabled="page.page == page.pageCount"
                @click="show(page.pageCount)"
                class="btn-prev"
                >
            尾页
        </button>
    </el-pagination>
</div>

生成的界面如下

posted on   随缘而处  阅读(3534)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· 从HTTP原因短语缺失研究HTTP/2和HTTP/3的设计差异
· 三行代码完成国际化适配,妙~啊~

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
点击右上角即可分享
微信分享提示