美文网首页
ant-design-vue 纯前端分页

ant-design-vue 纯前端分页

作者: 哈哈乐乐WXT | 来源:发表于2020-05-26 10:11 被阅读0次

由于项目需求需要采取前端分页方式,最后找到解决方式

<a-table
        size="default"
        bordered
        :columns="columns"
        :dataSource="dataSource"
        :loading="loading"
        :pagination="false"
      >
     ...此处省略部分代码
      </a-table>
      <a-pagination
        size="middle"
        v-model="current"
        :pageSize="pageSize"
        @change="pageNumberChange"
        @showSizeChange="sizeChange"
        :pageSizeOptions="sizeList"
        :total="total"
        showSizeChanger
        showQuickJumper
      />
    </div>

data中定义
   sizeList: ['5','10', '20', '30'], //一页能显示条数
   pageSize: 10, //当前页显示多少条
   current: 1, //当前页
   total: 0, //总条数,在获取后台数据时将数组的length赋值给total

分页操作
//分页页数的改变
pageNumberChange(current, size) {
     this.current = current;
     this.pageSize = size;
     this.dataSource = this.getShowSource();
   },
 //  分页显示条数的变化
sizeChange(current, size) {
     this.current = current;
     this.pageSize = size;
     this.dataSource = this.getShowSource();
   },
//实现分页效果
getShowSource() {
     var keyValue = 0;
     var data = this.showSource;//后端返回的全部数据
     for (var i = 0; i < data.length; i++) {
       keyValue = keyValue + 1;
       let key = { key: keyValue };
       data[i] = Object.assign(data[i], key);
     }
     var start = this.pageSize * this.current - this.pageSize;
     var end = this.pageSize * this.current;
     return data.slice(start, end);
   },

*参考地址:https://blog.csdn.net/weixin_39040527/article/details/105550569

相关文章

网友评论

      本文标题:ant-design-vue 纯前端分页

      本文链接:https://www.haomeiwen.com/subject/rwkmahtx.html