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

相关文章

HTML5的input标签的`type`属性值详解和代码示例

《HTML5的input标签的`type`属性值详解和代码示例》HTML5的`input`标签提供了多种`type`属性值,用于创建不同类型的输入控件,满足用户输入的多样化需求,从文本输入、密码输入、... 目录一、引言二、文本类输入类型2.1 text2.2 password2.3 textarea(严格

SpringBoot返回文件让前端下载的几种方式

《SpringBoot返回文件让前端下载的几种方式》文章介绍了开发中文件下载的两种常见解决方案,并详细描述了通过后端进行下载的原理和步骤,包括一次性读取到内存和分块写入响应输出流两种方法,此外,还提供... 目录01 背景02 一次性读取到内存,通过响应输出流输出到前端02 将文件流通过循环写入到响应输出流

SpringBoot+Vue3整合SSE实现实时消息推送功能

《SpringBoot+Vue3整合SSE实现实时消息推送功能》在日常开发中,我们经常需要实现实时消息推送的功能,这篇文章将基于SpringBoot和Vue3来简单实现一个入门级的例子,下面小编就和大... 目录前言先大概介绍下SSE后端实现(SpringBoot)前端实现(vue3)1. 数据类型定义2.

前端Visual Studio Code安装配置教程之下载、汉化、常用组件及基本操作

《前端VisualStudioCode安装配置教程之下载、汉化、常用组件及基本操作》VisualStudioCode是微软推出的一个强大的代码编辑器,功能强大,操作简单便捷,还有着良好的用户界面,... 目录一、Visual Studio Code下载二、汉化三、常用组件1、Auto Rename Tag2

vite搭建vue3项目的搭建步骤

《vite搭建vue3项目的搭建步骤》本文主要介绍了vite搭建vue3项目的搭建步骤,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学... 目录1.确保Nodejs环境2.使用vite-cli工具3.进入项目安装依赖1.确保Nodejs环境

Nginx搭建前端本地预览环境的完整步骤教学

《Nginx搭建前端本地预览环境的完整步骤教学》这篇文章主要为大家详细介绍了Nginx搭建前端本地预览环境的完整步骤教学,文中的示例代码讲解详细,感兴趣的小伙伴可以跟随小编一起学习一下... 目录项目目录结构核心配置文件:nginx.conf脚本化操作:nginx.shnpm 脚本集成总结:对前端的意义很多

前端缓存策略的自解方案全解析

《前端缓存策略的自解方案全解析》缓存从来都是前端的一个痛点,很多前端搞不清楚缓存到底是何物,:本文主要介绍前端缓存的自解方案,文中通过代码介绍的非常详细,需要的朋友可以参考下... 目录一、为什么“清缓存”成了技术圈的梗二、先给缓存“把个脉”:浏览器到底缓存了谁?三、设计思路:把“发版”做成“自愈”四、代码

通过React实现页面的无限滚动效果

《通过React实现页面的无限滚动效果》今天我们来聊聊无限滚动这个现代Web开发中不可或缺的技术,无论你是刷微博、逛知乎还是看脚本,无限滚动都已经渗透到我们日常的浏览体验中,那么,如何优雅地实现它呢?... 目录1. 早期的解决方案2. 交叉观察者:IntersectionObserver2.1 Inter

Vue3视频播放组件 vue3-video-play使用方式

《Vue3视频播放组件vue3-video-play使用方式》vue3-video-play是Vue3的视频播放组件,基于原生video标签开发,支持MP4和HLS流,提供全局/局部引入方式,可监听... 目录一、安装二、全局引入三、局部引入四、基本使用五、事件监听六、播放 HLS 流七、更多功能总结在 v

利用Python操作Word文档页码的实际应用

《利用Python操作Word文档页码的实际应用》在撰写长篇文档时,经常需要将文档分成多个节,每个节都需要单独的页码,下面:本文主要介绍利用Python操作Word文档页码的相关资料,文中通过代码... 目录需求:文档详情:要求:该程序的功能是:总结需求:一次性处理24个文档的页码。文档详情:1、每个