VUE 页码分页封装

2024-04-19 20:12

本文主要是介绍VUE 页码分页封装,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

VUE 页码封装组件

pagination/index.vue :

<template><div class="pagination-contianer"><el-pagination background layout="prev, pager, next" :total="total" @current-change="currentChange"> </el-pagination></div>
</template>
<script>
export default {name: 'Pagination',props: {total: {type: Number,default: 0}},methods: {currentChange(current) {this.$emit('trigger-event', current)}}
}
</script>
<style lang="stylus" scoped>
.pagination-contianer {margin-top: 10px;text-align: right;
}/deep/ .el-pagination.is-background .el-pager li:not(.disabled).active {background-color: #387dff !important;color: #FFF;
}/deep/ .el-pagination.is-background .el-pager li {background-color: #1c1e22 !important;
}
/deep/ .el-pagination .btn-next, .el-pagination .btn-prev {background-color: #1c1e22 !important;
}
/deep/ .el-pagination.is-background .btn-prev {background-color: #1c1e22 !important;
}
</style>

table表页面,看文件结构:

views/defects/ index.vue 代码:

<template><div class="project-container"><div class="table"><DefectList :defect-list="keyword ? filterDefectList : defectList" :total="fetchListPageData.total" :on-page-change="pageChange" /></div></div>
</template><script lang="ts">
import Vue from 'vue'
import DefectList from './components/DefectList.vue'export default Vue.extend({name: 'Index',components: {DefectList// TypeIcon},data() {return {defectList: [],filterDefectList: [],placeholderWords: '搜索缺陷',keyword: '',fetchListPageData: {total: 0,page: 1,pageSize: 10}}},watch: {keyword(newVal) {const keyVal = newVal.replace(' ', '')this.filterDefectList = keyVal ? this.defectList.filter(item => item.title.includes(keyVal)) : this.defectList}},created() {this.getDefectList()},methods: {async getDefectList() {try {const res = await API.Defect.defectListData({keyword: '',page: this.fetchListPageData.page,pageSize: this.fetchListPageData.pageSize})this.defectList = res.data.listthis.fetchListPageData.total = res.data.total} catch (error) {warn(error, true)}},pageChange(current: number) {this.fetchListPageData.page = currentthis.getDefectList()}}
})
</script><style lang="stylus" scoped>
.project-container {.project-name {img {position: relative;top: 3px;}}
}
</style>

DefectList.vue

<template><div><div style="position: relative; transition: all ease 0.5s"><div class="block"><Pagination popper-class="sizes" :total="total" @trigger-event="getCurrentPageNum" /></div></div></div>
</template><script lang="ts">
import Vue from 'vue'
import Pagination from '@/components/Pagination/index.vue'export default Vue.extend({components: {Pagination},props: {total: {type: Number,default: 0},onPageChange: {type: Function,default: () => {}}},data() {return {}},methods: {getCurrentPageNum(current: number) {this.onPageChange(current)}}
})
</script>

这篇关于VUE 页码分页封装的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/918403

相关文章

CSS弹性布局常用设置方式

《CSS弹性布局常用设置方式》文章总结了CSS布局与样式的常用属性和技巧,包括视口单位、弹性盒子布局、浮动元素、背景和边框样式、文本和阴影效果、溢出隐藏、定位以及背景渐变等,通过这些技巧,可以实现复杂... 一、单位元素vm 1vm 为视口的1%vh 视口高的1%vmin 参照长边vmax 参照长边re

CSS3中使用flex和grid实现等高元素布局的示例代码

《CSS3中使用flex和grid实现等高元素布局的示例代码》:本文主要介绍了使用CSS3中的Flexbox和Grid布局实现等高元素布局的方法,通过简单的两列实现、每行放置3列以及全部代码的展示,展示了这两种布局方式的实现细节和效果,详细内容请阅读本文,希望能对你有所帮助... 过往的实现方法是使用浮动加

css渐变色背景|<gradient示例详解

《css渐变色背景|<gradient示例详解》CSS渐变是一种从一种颜色平滑过渡到另一种颜色的效果,可以作为元素的背景,它包括线性渐变、径向渐变和锥形渐变,本文介绍css渐变色背景|<gradien... 使用渐变色作为背景可以直接将渐China编程变色用作元素的背景,可以看做是一种特殊的背景图片。(是作为背

一文教你使用Python实现本地分页

《一文教你使用Python实现本地分页》这篇文章主要为大家详细介绍了Python如何实现本地分页的算法,主要针对二级数据结构,文中的示例代码简洁易懂,有需要的小伙伴可以了解下... 在项目开发的过程中,遇到分页的第一页就展示大量的数据,导致前端列表加载展示的速度慢,所以需要在本地加入分页处理,把所有数据先放

C++实现封装的顺序表的操作与实践

《C++实现封装的顺序表的操作与实践》在程序设计中,顺序表是一种常见的线性数据结构,通常用于存储具有固定顺序的元素,与链表不同,顺序表中的元素是连续存储的,因此访问速度较快,但插入和删除操作的效率可能... 目录一、顺序表的基本概念二、顺序表类的设计1. 顺序表类的成员变量2. 构造函数和析构函数三、顺序表

Redis存储的列表分页和检索的实现方法

《Redis存储的列表分页和检索的实现方法》在Redis中,列表(List)是一种有序的数据结构,通常用于存储一系列元素,由于列表是有序的,可以通过索引来访问元素,因此可以很方便地实现分页和检索功能,... 目录一、Redis 列表的基本操作二、分页实现三、检索实现3.1 方法 1:客户端过滤3.2 方法

CSS自定义浏览器滚动条样式完整代码

《CSS自定义浏览器滚动条样式完整代码》:本文主要介绍了如何使用CSS自定义浏览器滚动条的样式,包括隐藏滚动条的角落、设置滚动条的基本样式、轨道样式和滑块样式,并提供了完整的CSS代码示例,通过这些技巧,你可以为你的网站添加个性化的滚动条样式,从而提升用户体验,详细内容请阅读本文,希望能对你有所帮助...

css实现图片旋转功能

《css实现图片旋转功能》:本文主要介绍了四种CSS变换效果:图片旋转90度、水平翻转、垂直翻转,并附带了相应的代码示例,详细内容请阅读本文,希望能对你有所帮助... 一 css实现图片旋转90度.icon{ -moz-transform:rotate(-90deg); -webkit-transfo

Go语言利用泛型封装常见的Map操作

《Go语言利用泛型封装常见的Map操作》Go语言在1.18版本中引入了泛型,这是Go语言发展的一个重要里程碑,它极大地增强了语言的表达能力和灵活性,本文将通过泛型实现封装常见的Map操作,感... 目录什么是泛型泛型解决了什么问题Go泛型基于泛型的常见Map操作代码合集总结什么是泛型泛型是一种编程范式,允

vue基于ElementUI动态设置表格高度的3种方法

《vue基于ElementUI动态设置表格高度的3种方法》ElementUI+vue动态设置表格高度的几种方法,抛砖引玉,还有其它方法动态设置表格高度,大家可以开动脑筋... 方法一、css + js的形式这个方法需要在表格外层设置一个div,原理是将表格的高度设置成外层div的高度,所以外层的div需要