ant design vue table分页设置

1、设置pagination

 <a-table :columns="columns" :dataSource="data" :rowSelection="rowSelection" :pagination="pagination">
     <a slot="action" href="javascript:;">查看</a>
     <img  style="width:20px;heigth:20px" slot="pic" slot-scope="text" :src=text />
  </a-table>

2、自定义pagination,注意写成onChange,change不行,灰色部分请根据自己实际代码修改。

 

data () {
    let self = this
    return {
      collapsed: false,
      data,
      sels,
      columns,
      rowSelection,
      pagination: {
        pageNo: 1,
        pageSize: 20, // 默认每页显示数量
        showSizeChanger: true, // 显示可改变每页数量
        pageSizeOptions: ['10', '20', '50', '100'], // 每页数量选项
        showTotal: total => `共 ${total} 条`, // 显示总数
        onShowSizeChange: (current, pageSize) => this.onSizeChange(current, pageSize), // 改变每页数量时更新显示
        onChange:(page,pageSize)=>this.onPageChange(page,pageSize),//点击页码事件
        total:0 //总条数
       }
    }
  },
methods: {
 	onPageChange(page, pageSize) {
      this.pagination.pageNo = page
       this.getList()
   },
   onSizeChange(current, pageSize) {
       this.pagination.pageNo = 1
       this.pagination.pageSize = pageSize
       this.getList()
   }
}

3、Ajax读取数据列表时,pagination.total赋总条数即可

.then((response) => {
          this.data = response.data.items
          this.pagination.total=response.data.totalNum
          console.log(response)
        })

4.读取数据时带上当前页、分页大小,过滤条件,后端代码可以简单使用通用分页方法返回Json数据即可

getList () {
      let filter= {xxx:this.queryParam.xxx,curPage:this.pagination.pageNo,pageSize:this.pagination.pageSize};// 请求参数
      console.log(filter) 
      this.getData(filter)
    },

Logo

前往低代码交流专区

更多推荐