Vue+element-ui 实现表格的分页功能示例


Posted in Javascript onAugust 18, 2018

本文介绍了Vue+element-ui 实现表格的分页功能示例,分享给大家,具体如下:

实现效果如下图所示:

Vue+element-ui 实现表格的分页功能示例

template部分:

<el-table
  :data="tempList"
  :header-cell-style="rowClass"
  stripe
  border style="margin-bottom:14px;"
  :empty-text="emptyText">
  <el-table-column property="name" label="债券名称" width="228"></el-table-column>
  <el-table-column property="marketValue" label="市值" width="228" align="right" :formatter="formatDecimal2"></el-table-column>
  <el-table-column property="type" label="债券类型"></el-table-column>
  <el-table-column property="ratio" label="占母基金的比重" align="right" :formatter="toPercent"></el-table-column>
</el-table>
<div class="paginationClass">
  <el-pagination
  @size-change="handleSizeChange1"
  @current-change="handleCurrentChange1" :current-page="currentPage1"
  :page-sizes="[10, 20, 50, 100]"
  :page-size="pageSize" layout="total, sizes, prev, pager, next, jumper"
  :total="total1">
  </el-pagination>

</div>

数据部分:获取测试的数据(19个)

data() {
  return {
     total1: 0,
     currentPage1:1,
     pageSize:10,
     bondsAllList: [{
      "name": "16协信01",
      "marketValue": 691861.0999317318,
      "type": "信用债",
      "ratio": 0.0027959958264152343
    }, {
      "name": "16朗诗01",
      "marketValue": 690131.4471819025,
      "type": "信用债",
      "ratio": 0.002789005836849196
    }, { 
      "name": "16三盛01",
      "marketValue": 688816.9110920322, 
      "type": "信用债",
      "ratio": 0.0027836934447790073
    }, { 
      "name": "17三鼎01",
      "marketValue": 685426.7917023668, 
      "type": "信用债",
      "ratio": 0.002769993065229573
    }, { 
      "name": "16临开债",
      "marketValue": 676640.4401650192, 
      "type": "信用债",
      "ratio": 0.00273448506769905
    }, { 
      "name": "16华讯01",
      "marketValue": 614990.17198298, 
      "type": "信用债",
      "ratio": 0.0024853398381849607
    }, { 
      "name": "16花样03",
      "marketValue": 614990.0028613778, 
      "type": "信用债",
      "ratio": 0.0024853391547193142
    }, { 
      "name": "15协信01",
      "marketValue": 614987.6443837617, 
      "type": "信用债",
      "ratio": 0.0024853296234802085
    }, { 
      "name": "16三盛03",
      "marketValue": 461240.73328782123, 
      "type": "信用债",
      "ratio": 0.0018639972176101563
    }, { 
      "name": "16山钢03",
      "marketValue": 384367.27773985104, 
      "type": "信用债",
      "ratio": 0.0015533310146751303
    }, { 
      "name": "14甘公01",
      "marketValue": 324002.01240352966, 
      "type": "信用债",
      "ratio": 0.0013093788254893862
    }, { 
      "name": "15新湖债",
      "marketValue": 307493.82219188084, 
      "type": "信用债",
      "ratio": 0.0012426648117401043
    }, { 
      "name": "16珠管01",
      "marketValue": 303035.16177009855, 
      "type": "信用债",
      "ratio": 0.0012246461719698726
    }, { 
      "name": "16重机债",
      "marketValue": 299103.36126325984, 
      "type": "信用债",
      "ratio": 0.0012087567140880767
    }, { 
      "name": "17三鼎01",
      "marketValue": 8163.960979194436, 
      "type": "信用债",
      "ratio": 3.2992750751699765E-5
    }, { 
      "name": "16重机债",
      "marketValue": 1475.2323613477674, 
      "type": "信用债",
      "ratio": 5.961808700804324E-6
    }, { 
      "name": "14甘公01",
      "marketValue": 723.1485963397557, 
      "type": "信用债",
      "ratio": 2.92243697100979E-6
    }, { 
      "name": "15新湖债",
      "marketValue": 707.2357910413259, 
      "type": "信用债",
      "ratio": 2.85812906700224E-6
    }, { 
      "name": "16珠管01",
      "marketValue": 153.74691109594042, 
      "type": "信用债",
      "ratio": 6.213324058700521E-7
    }]
  }
}

methiods部分:

methods:{
  handleSizeChange1: function(pageSize) { // 每页条数切换
    this.pageSize = pageSize
    this.handleCurrentChange1(this.currentPage1);
  },
  handleCurrentChange1: function(currentPage) {//页码切换
    this.currentPage1 = currentPage
    this.currentChangePage(this.bondsAllList,currentPage)
    
  },
  //分页方法(重点)
  currentChangePage(list,currentPage) { 
   let from = (currentPage - 1) * this.pageSize;
   let to = currentPage * this.pageSize;
   this.tempList = [];
   for (; from < to; from++) {
    if (list[from]) {
     this.tempList.push(list[from]);
    }
   }
  },
}

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持三水点靠木。

Javascript 相关文章推荐
js中的string.format函数代码
Aug 11 Javascript
设为首页加入收藏兼容360/火狐/谷歌/IE等主流浏览器的代码
Mar 26 Javascript
基于js disabled=&quot;false&quot;不起作用的解决办法
Jun 26 Javascript
点击弹出层外区域关闭弹出层jquery特效示例
Aug 25 Javascript
全面理解JavaScript中的闭包
May 12 Javascript
jQuery添加options点击事件并传值实例代码
May 18 Javascript
浅谈js多维数组和hash数组定义和使用
Jul 27 Javascript
拖动时防止选中
Feb 03 Javascript
JavaScript类数组对象转换为数组对象的方法实例分析
Jul 24 Javascript
jquery 通过ajax请求获取后台数据显示在表格上的方法
Aug 08 jQuery
详解Vue项目引入CreateJS的方法(亲测可用)
May 30 Javascript
记一次vue跨域的解决
Oct 21 Javascript
vue下history模式刷新后404错误解决方法
Aug 18 #Javascript
详解javascript appendChild()的完整功能
Aug 18 #Javascript
vue中的自定义分页插件组件的示例
Aug 18 #Javascript
vue 自定义提示框(Toast)组件的实现代码
Aug 17 #Javascript
微信小程序实现即时通信聊天功能的实例代码
Aug 17 #Javascript
在iFrame子页面里实现模态框的方法
Aug 17 #Javascript
layer弹出层 iframe层去掉滚动条的实例代码
Aug 17 #Javascript
You might like
一条久听不愿放下的DIY森海MX500,三言两语话神奇
2021/03/02 无线电
php class中public,private,protected的区别以及实例分析
2013/06/18 PHP
zend Framework中的Layout(模块化得布局)详解
2013/06/28 PHP
php的sso单点登录实现方法
2015/01/08 PHP
php获取远程文件内容的函数
2015/11/02 PHP
PHP 极验验证码实例讲解
2016/09/29 PHP
php获取目录下所有文件及目录(多种方法)(推荐)
2019/05/14 PHP
php常用日期时间函数实例小结
2019/07/04 PHP
解决laravel中日志权限莫名变成了root的问题
2019/10/17 PHP
php使用goto实现自动重启swoole、reactphp、workerman服务的代码
2020/04/13 PHP
在JavaScript的正则表达式中使用exec()方法
2015/06/16 Javascript
jQuery中借助deferred来请求及判断AJAX加载的实例讲解
2016/05/24 Javascript
vue实现底部菜单功能
2018/07/24 Javascript
基于vue.js实现购物车
2020/01/15 Javascript
jQuery实现数字华容道小游戏(实例代码)
2020/01/16 jQuery
javascript中innerHTML 获取或替换html内容的实现代码
2020/03/17 Javascript
ES6 Generator基本使用方法示例
2020/06/06 Javascript
echarts实现获取datazoom的起始值(包括x轴和y轴)
2020/07/20 Javascript
详解阿里Node.js技术文档之process模块学习指南
2021/01/04 Javascript
[05:15]2018年度CS GO社区贡献奖-完美盛典
2018/12/16 DOTA
Python ljust rjust center输出
2008/09/06 Python
python开发之IDEL(Python GUI)的使用方法图文详解
2015/11/12 Python
Pandas Shift函数的基础入门学习笔记
2018/11/16 Python
python 监听salt job状态,并任务数据推送到redis中的方法
2019/01/14 Python
python读取ini配置的类封装代码实例
2020/01/08 Python
pytorch实现对输入超过三通道的数据进行训练
2020/01/15 Python
Python中and和or如何使用
2020/05/28 Python
利用Bootstrap实现漂亮简洁的CSS3价格表实例源码
2017/03/02 HTML / CSS
简单的HTML5初步入门教程
2015/09/29 HTML / CSS
保卫科工作岗位职责
2014/03/01 职场文书
2014年党的群众路线教育实践活动总结
2014/04/25 职场文书
授权委托书格式
2014/07/31 职场文书
前台接待岗位职责范本
2015/04/03 职场文书
学生会干部任命书
2015/09/21 职场文书
「玫瑰之王的葬礼」舞台剧主视觉图公开
2022/03/21 日漫
代码复现python目标检测yolo3详解预测
2022/05/06 Python