elementui 实现一个固定位置的Pagination(分页)组件

系列文章目录

一、elementui 导航菜单栏和Breadcrumb 面包屑关联

二、elementui 左侧导航菜单栏与main区域联动

三、elementui 中设置图片的高度并支持PC和手机自适应

四、 elementui 实现一个固定位置的Pagination(分页)组件



前言

在Element UI中,要实现一个固定位置的Pagination(分页)组件,可以使用CSS来固定Pagination的位置,并将Pagination组件包裹在一个固定位置的容器中。


一、实现效果

在该网页的右下角固定位置
在这里插入图片描述

二、实现步骤

PS:针对有一点点vue基础的新手

1.添加Pagination组件

在你的Vue组件中添加Pagination组件

 <!--添加Pagination组件-->
 <div class="pagination-container">
     <el-pagination
             @size-change="handleSizeChange"
             @current-change="handleCurrentChange"
             :current-page="currentPage"
             :page-sizes="[4, 8, 12]"
             :page-size="pageSize"
             layout="total, sizes, prev, pager, next, jumper"
             :total="total">
     </el-pagination>
 </div>

<script>
    export default {
        name: "FileView",
        data() {
            return {
                currentPage: 1,
                pageSize: 8,
                total: 10,
            };
        },
        computed: {
            currentPageData() {
                return this.items.slice((this.currentPage - 1) * this.pageSize, this.currentPage * this.pageSize);
            }
        },
        methods: {
            handleSizeChange(val) {
                this.pageSize = val;
                this.currentPage = 1;
            },
            handleCurrentChange(val) {
                this.currentPage = val;
            }
        }
    };
</script>

2.CSS样式代码

在你的样式文件中(例如

<style scoped>
    .maindiv {
        /* 确保.maindiv 是Pagination的父容器 */
        position: relative;
        height: 580px; /* 或者其他高度以确保Pagination下方有足够空间 */
    }
    .pagination-container {
        position: absolute; /* 固定位置 */
        bottom: 10px; /* 距离底部10像素 */
        right: 10px; /* 距离右侧10像素 */
    }
</style>

三、完整代码

 <template>
    <div class="maindiv">
        <el-row>
            <el-col :span="6" v-for="(item, index) in currentPageData" :key="index" style="padding: 3px;">
                <el-card  :body-style="{ padding: '0px' }">
                    <img v-if="item.image" :src="item.image" class="image">
                    <div style="padding: 14px;">
                        <span>{{ item.title }}</span>
                        <div class="bottom clearfix">
                            <time class="time">{{ item.time }}</time>
                            <el-button type="text" class="button">操作按钮</el-button>
                        </div>
                    </div>
                </el-card>
            </el-col>
        </el-row>
        <!--添加Pagination组件-->
        <div class="pagination-container">
            <el-pagination
                    @size-change="handleSizeChange"
                    @current-change="handleCurrentChange"
                    :current-page="currentPage"
                    :page-sizes="[4, 8, 12]"
                    :page-size="pageSize"
                    layout="total, sizes, prev, pager, next, jumper"
                    :total="total">
            </el-pagination>
        </div>
    </div>
</template>

<script>
    export default {
        name: "FileView",
        data() {
            return {
                currentPage: 1,
                pageSize: 8,
                total: 10,
                items: [
                    {
                        image:"https://img0.baidu.com/it/u=3558402622,3525872153&fm=253&fmt=auto&app=138&f=JPEG?w=718&h=500",
                        title:"好吃的汉堡",
                        time:"2024-03-25"
                    }
                    // 填充你的数据对象,每个对象包含 'image', 'title', 'time' 属性
                ]
            };
        },
        computed: {
            currentPageData() {
                return this.items.slice((this.currentPage - 1) * this.pageSize, this.currentPage * this.pageSize);
            }
        },
        methods: {
            handleSizeChange(val) {
                this.pageSize = val;
                this.currentPage = 1;
            },
            handleCurrentChange(val) {
                this.currentPage = val;
            }
        }
    };
</script>
<style scoped>
    .time {
        font-size: 13px;
        color: #999;
    }
    .bottom {
        margin-top: 13px;
        line-height: 12px;
    }
    .button {
        padding: 0;
        float: right;
    }
    .clearfix:before,
    .clearfix:after {
        display: table;
        content: "";
    }
    .clearfix:after {
        clear: both
    }
    .image {
        width: 100%;
        display: block;
    }
    .maindiv {
        /* 确保.maindiv 是Pagination的父容器 */
        position: relative;
        height: 580px; /* 或者其他高度以确保Pagination下方有足够空间 */
    }
    .pagination-container {
        position: absolute; /* 固定位置 */
        bottom: 10px; /* 距离底部10像素 */
        right: 10px; /* 距离右侧10像素 */
    }
</style>

相关推荐

  1. react基于antd二次封装组件Pagination

    2024-04-04 06:20:05       37 阅读
  2. DjangoORM使用filter以及Paginator

    2024-04-04 06:20:05       10 阅读

最近更新

  1. TCP协议是安全的吗?

    2024-04-04 06:20:05       18 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-04-04 06:20:05       19 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-04-04 06:20:05       18 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-04-04 06:20:05       20 阅读

热门阅读

  1. 《迭代器模式(极简c++)》

    2024-04-04 06:20:05       16 阅读
  2. 常见网络问题的概述

    2024-04-04 06:20:05       10 阅读
  3. 通过TCP或UDP向某个IP和端口发送数据

    2024-04-04 06:20:05       13 阅读
  4. 新兴AI技术及其创业机会

    2024-04-04 06:20:05       17 阅读
  5. 【开源产品部署系列】一、RuoYi-Radius搭建流程

    2024-04-04 06:20:05       14 阅读
  6. Pytorch torch.utils.data.DataLoader 用法详细介绍

    2024-04-04 06:20:05       16 阅读
  7. Ubuntu 如何移动硬盘在所有账号都分享

    2024-04-04 06:20:05       14 阅读
  8. C/C++混合项目,程序运行报错:未定义函数符号

    2024-04-04 06:20:05       11 阅读
  9. HTML优化SEO的实用技巧

    2024-04-04 06:20:05       16 阅读