vue+Element-ui实现分页效果

作者:yusirxiaer 时间:2024-04-26 17:38:17 

本文实例为大家分享了vue+Element-ui实现分页效果的具体代码,供大家参考,具体内容如下

当我们向后台请求大量数据的时候,并要在页面展示出来,请求的数据可能上百条数据或者更多的时候,并不想在一个页面展示,这就需要使用分页功能来去完成了。

1.本次所使用的是vue2.0+element-ui实现一个分页功能,element-ui这个组件特别丰富,分页中给我提供了一个Pagination 分页,使用Pagination 快速完成分页功能

最终效果展示

vue+Element-ui实现分页效果


<div class="deit">
<div class="crumbs">
 <el-breadcrumb separator="/">
  <el-breadcrumb-item><i class="el-icon-date"></i> 数据管理</el-breadcrumb-item>
  <el-breadcrumb-item>用户列表</el-breadcrumb-item>
 </el-breadcrumb>
 <div class="cantainer">
    <el-table style="width: 100%;"
    :data="userList.slice((currentPage-1)*pagesize,currentPage*pagesize)" //对数据请求的处理,最为重要的一句话
    >
     <el-table-column type="index" width="50">
     </el-table-column>
     <el-table-column label="日期" prop="date" width="180">
     </el-table-column>
     <el-table-column label="用户姓名" prop="name" width="180">
     </el-table-column>
     <el-table-column label="邮箱" prop="email" width="180">
     </el-table-column>
     <el-table-column label="地址" prop="address" width="200">
     </el-table-column>
    </el-table>
     <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="currentPage"
      :page-sizes="[5, 10, 20, 40]" //这是下拉框可以选择的,每选择一行,要展示多少内容
      :page-size="pagesize"   //显示当前行的条数
      layout="total, sizes, prev, pager, next, jumper"
      :total="userList.length"> //这是显示总共有多少数据,
    </el-pagination>
 </div>
</div>
</div>

需要data定义一些,userList定义一个空数组,请求的数据都是存放这里面 


data () {
 return {
   currentPage:1, //初始页
   pagesize:10, // 每页的数据
   userList: []
 }
},

对一些数据,方法处理,数据的来源是自己通过json-server搭建的本地数据,通过vue-resource请求数据,


created() {
 this.handleUserList()
},
methods: {
 // 初始页currentPage、初始每页数据数pagesize和数据data
 handleSizeChange: function (size) {
   this.pagesize = size;
   console.log(this.pagesize) //每页下拉显示数据
 },
 handleCurrentChange: function(currentPage){
   this.currentPage = currentPage;
   console.log(this.currentPage) //点击第几页
 },
 handleUserList() {
  this.$http.get('http://localhost:3000/userList').then(res => { //这是从本地请求的数据接口,
   this.userList = res.body
  })
 }
}

以上都是分页所需的功能,也是自己在自己写案例中所遇到的,并总结下方便查看,喜欢的可以关注一下

关于vue.js的学习教程,请大家点击专题vue.js组件学习教程、Vue.js前端组件学习教程进行学习。

来源:https://blog.csdn.net/yusirxiaer/article/details/103201728

标签:vue,分页
0
投稿

猜你喜欢

  • Go每日一库之dateparse处理时间

    2024-04-26 17:25:55
  • Python中列表(list)操作方法汇总

    2023-11-12 06:16:33
  • MySQL创建定时任务

    2024-01-20 15:59:34
  • Django REST Swagger实现指定api参数

    2023-03-10 05:48:58
  • SQL Server 2008中有关XML的新功能

    2008-06-04 12:57:00
  • JS对象数组中如何匹配某个属性值

    2024-04-18 09:39:42
  • Python图片处理之图片采样处理详解

    2021-01-14 12:58:36
  • Bootstrap响应式侧边栏改进版

    2023-08-17 02:26:10
  • 浅谈Python中函数的定义及其调用方法

    2022-09-01 09:35:35
  • MYSQL建立外键失败几种情况记录Can't create table不能创建表

    2024-01-22 19:57:22
  • python使用pymysql实现操作mysql

    2024-01-15 17:32:17
  • 一种简单的ID生成策略: Mysql表生成全局唯一ID的实现

    2024-01-25 09:55:41
  • pytest实现多进程与多线程运行超好用的插件

    2023-03-23 15:56:23
  • 使用PIL(Python-Imaging)反转图像的颜色方法

    2022-12-15 19:16:48
  • Go Gin实现文件上传下载的示例代码

    2023-06-21 15:11:13
  • 基于JavaScript实现单选框下拉菜单添加文件效果

    2023-07-15 08:46:33
  • js弹出新窗口而不会被浏览器阻止的方法

    2010-04-06 12:38:00
  • Python中输入和输出(打印)数据实例方法

    2021-03-25 22:32:11
  • 怎样生成utf-8编码的html文件

    2009-03-11 19:34:00
  • 利用box-sizing实现div仿框架

    2009-12-08 15:45:00
  • asp之家 网络编程 m.aspxhome.com