当前位置: 首页 > news >正文

Vue3.x+Element Plus仿制Acro Design简洁模式分页器组件

Vue3.x+Element Plus仿制Acro Design简洁模式分页器组件

  • 开发中难免会遇到宽度很窄的列表需要使用分页器的情况,这时若使用Element Plus组件的分页器会导致分页器内容超出展示的区域,而Element Plus组件中目前没有Acro Design那样小巧的分页器(Arco Design Vue)如下图所示,如果再引入一个新的UI组件库未免导致项目臃肿,所以基于Vue3.xElement Plus封装了一个即拿即用的”简洁模式“分页器组件以便不时之需
    在这里插入图片描述

  • 分页器组件代码部分:

<!-- (简洁模式)分页器组件 -->
<template><div class="smallpagination"><!-- 总数统计 --><span>{{ '共' + total + '条' }}</span><!-- 翻页 --><div class="smallpagination-pager"><!-- 左翻页 --><el-icon @click="pageTurning('down')" :class="curPage <= 1 ? 'forbid-pageturning' : ''"><ArrowLeft /></el-icon><!-- 页码 --><el-input-number @change="handlePageChange" v-model="pageNum" :min="1" :max="pageTotal" :step-strictly="true":controls="false" /><b>{{ '/ ' + pageTotal }}</b><!-- 右翻页 --><el-icon @click="pageTurning('up')" :class="curPage >= pageTotal ? 'forbid-pageturning' : ''"><ArrowRight /></el-icon></div></div>
</template><script setup>
import { useAttrs, computed, ref } from 'vue';
import {ArrowLeft,ArrowRight
} from '@element-plus/icons-vue';// 接收父组件参数
const attrs = useAttrs();
// 父组件事件
const em = defineEmits(['handlePageChange']);
// 当前页
const pageNum = ref(1);
// 父组件传递-当前页码
const curPage = computed(() => {pageNum.value = attrs.curPage;return attrs.curPage;
});
// 父组件传递-总数
const total = computed(() => {return attrs.total;
});
// 总页码数
const pageTotal = computed(() => {return attrs.total > 0 ? Math.ceil(attrs.total / attrs.pageSize) : 1;
});/* 改变页码 */
const handlePageChange = (e) => {if (pageTotal.value <= 1) {return;}em('handlePageChange', e);
};
/* 翻页 */
const pageTurning = (type) => {// 向前翻页if (type === 'up') {if (curPage.value >= pageTotal.value || pageTotal.value <= 1) {return;}em('handlePageChange', pageNum.value + 1);}// 向后翻页else {if (pageTotal.value <= 1 || curPage.value <= 1) {return;}em('handlePageChange', pageNum.value - 1);}
};
</script><style lang="less" scoped>
.smallpagination {width: auto;height: 100%;display: flex;align-items: center;>span {margin-right: 11px;font-size: 14px;font-weight: 400;color: #4E5969;line-height: 21px;}.smallpagination-pager {display: flex;align-items: center;.el-icon {width: 30px;height: 30px;font-size: 14px;color: #4E5969;cursor: pointer;&:hover {background: rgb(247, 248, 250);color: #0082ff;}}.forbid-pageturning {opacity: 0.4;cursor: not-allowed;&:active {color: #4E5969;background: rgb(255, 255, 255);}}>b {margin: 0 5px;font-size: 14px;font-weight: 400;color: #4E5969;}}
}
</style>
<style lang="less">
.smallpagination {.smallpagination-pager {.el-input-number {width: 40px;margin-left: 5px;span {display: none;}.el-input__wrapper {padding: 0;height: 30px;font-size: 14px;box-sizing: border-box;background: #f2f3f5;box-shadow: none !important;}}}
}
</style>
  • 使用简洁模式分页器组件代码如下:
<template><div class="xxx-list">...<div class="list-bottom-common-page"><SmallPagination :total="total" :curPage="curPage" :pageSize="pageSize" @handlePageChange="handleCurrentChange"></SmallPagination></div></div>
</template><script setup>
import SmallPagination from '@/components/xxx/SmallPagination.vue';
import { ref } from 'vue';// 当前页
const curPage = ref(1);
// 每页条数
const pageSize = ref(20);
// 列表总数
const total = ref(0);/* 当前页改变 */
const handleCurrentChange = (val) => {curPage.value = val;...
};
</script>
  • 最终效果如下:
    在这里插入图片描述
http://www.lryc.cn/news/15547.html

相关文章:

  • 经典文献阅读之--VoxelMap(体素激光里程计)
  • .NET6中使用GRPC详细描述
  • ML@矩阵微积分基础
  • 华为OD机试真题Python实现【优秀学员统计】真题+解题思路+代码(20222023)
  • docsify在线文档支持pdf查看
  • ES6中Set类型的基本使用
  • 【VUE3.0_CSS功能】
  • 微机原理复习总结6:汇编语言程序设计
  • 计算机网络 部分原理和过程
  • C++实现链表
  • MySQL索引篇
  • Ardiuno-交通灯
  • Leetcode.1234 替换子串得到平衡字符串
  • 聚类算法之K-means算法详解
  • 电话呼入/呼出CSFB流程介绍
  • 【比赛合集】9场可报名的「创新应用」、「程序设计」大奖赛,任君挑选!
  • 剑指 Offer 27. 二叉树的镜像
  • RPC编程:RPC概述和架构演变
  • 神经网络训练时只对指定的边更新参数
  • Python列表list操作-遍历、查找、增加、删除、修改、排序
  • Python开发-学生管理系统
  • 大数据处理 - Trie树/数据库/倒排索引
  • jjava企业级开发-01
  • 「事务一致性」事务afterCommit
  • 【深度学习编译器系列】2. 深度学习编译器的通用设计架构
  • 图解操作系统
  • 【发版或上线项目保姆级心得】
  • Python数据分析-pandas库入门
  • MacBook Pro 恢复出厂设置
  • googletest 笔记