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

分页器封装

项目场景:

提示:这里简述项目相关背景:

在做项目中,我们对于一般的element组件使用时都会进行二次封装,这个就是对分页器的封装


方案:

提示:这里填写该问题的具体解决方案:

 1:组件

<template><div :class="{ 'hidden': hidden }" class="pagination-container"><el-pagination:background="background"v-model:current-page="currentPage"v-model:page-size="pageSize":layout="layout":page-sizes="pageSizes":total="total"@size-change="handleSizeChange"@current-change="handleCurrentChange"/></div>
</template><script setup>
import { scrollTo } from '@/utils/scroll-to'const props = defineProps({total: {required: true,type: Number},page: {type: Number,default: 1},limit: {type: Number,default: 10},pageSizes: {type: Array,default() {return [10, 20, 30, 50]}},// 移动端页码按钮的数量端默认值5pagerCount: {type: Number,default: document.body.clientWidth < 992 ? 5 : 7},layout: {type: String,default: 'total, sizes, prev, pager, next, jumper'},background: {type: Boolean,default: true},autoScroll: {type: Boolean,default: true},hidden: {type: Boolean,default: false}
})const emit = defineEmits();
const currentPage = computed({get() {return props.page},set(val) {emit('update:page', val)}
})
const pageSize = computed({get() {return props.limit},set(val){emit('update:limit', val)}
})
function handleSizeChange(val) {if (currentPage.value * val > props.total) {currentPage.value = 1}emit('pagination', { page: currentPage.value, limit: val })if (props.autoScroll) {// scrollTo(0, 800)}
}
function handleCurrentChange(val) {emit('pagination', { page: val, limit: pageSize.value })if (props.autoScroll) {// scrollTo(0, 800)}
}</script><style scoped>
.pagination-container {background: #fff;
}
.pagination-container.hidden {display: none;
}
</style>

2:使用

<Pagination:total="pageData.total":limit="pageData.pageSize":page="pageData.currentPage"@pagination="changePage"/>//引入组件
import Pagination from '@/components/Pagination/index.vue'// 页码切换
const pageData=reactive({currentPage:1,pageSize:10,total:100,
})
// 修改页码 与当前页
const changePage=(val)=>{pageData.currentPage=val.page;pageData.pageSize=val.limit;console.log("ccccccccccccccccccccccccc",val)getTableList();//获取页码更新后数据
}

3: 效果

http://www.lryc.cn/news/575007.html

相关文章:

  • mongodb 新手入门,原理,优化,详细介绍 附上代码
  • github 上的php项目
  • 【LLaMA-Factory 实战系列】四、API 篇 - 部署推理服务与批量调用实战
  • Vue 3 响应式核心:深入理解 ref 与 reactive 的选择之道
  • Java中的synchronized和锁
  • 在NPU平台上,如何尝试跑通Ktransformers + DeepSeek R1?
  • 基于LangChat搭建RAG与Function Call结合的聊天机器人方案
  • 前端使用rtsp视频流接入海康威视摄像头
  • QT 学习笔记摘要(三)
  • HCIA-IP路由基础
  • C++ 多线程深度解析:掌握并行编程的艺术与实践
  • 基于CMS的黄道吉日万年历源码(自适应)
  • 商务年度总结汇报PPT模版分享
  • 板凳-------Mysql cookbook学习 (十--10)
  • LeetCode 3258.统计满足K约束的子字符串数量1
  • HTML表单元素
  • 线性结构之链表
  • 深度学习实战112-基于大模型Qwen+RAG+推荐算法的作业互评管理系统设计与实现
  • 机器学习01
  • SpringBoot高校党务系统
  • SpringBoot项目快速开发框架JeecgBoot——数据访问!
  • ros (二) 使用消息传递点云+rviz显示
  • Happy-LLM-Task06 :3.1 Encoder-only PLM
  • C++设计模式(GOF-23)——04 C++装饰器模式(Decorator)(一个类同时继承和组合另一个类)解决类爆炸问题、模板装饰器
  • python3文件操作
  • Node.js特训专栏-实战进阶:8. Express RESTful API设计规范与实现
  • python的智慧养老院管理系统
  • klayout db::edge 里的 crossed_by_point 的坑点
  • mbedtls ssl handshake error,res:-0x2700
  • 从零开始的云计算生活——第二十三天,稍作休息,Tomcat