Skip to content
On this page

usePaginationTable

示例

ID姓名

No Data

数据展示
接管表格中的查询、分页事件
<script setup lang="ts">
import { usePaginationTable } from '@hooks/components'

function getPaginationData() {
  return new Promise((resolve) => {
    setTimeout(() => {
      resolve({
        total: 10,
        current: 1,
        pageSize: 10,
        data: [
          {
            id: 1,
            name: '张三'
          },
          {
            id: 2,
            name: '李四'
          },
          {
            id: 3,
            name: '王五'
          },
          {
            id: 4,
            name: '赵六'
          },
          {
            id: 5,
            name: '田七'
          },
          {
            id: 6,
            name: '张三'
          },
          {
            id: 7,
            name: '李四'
          },
          {
            id: 8,
            name: '王五'
          },
          {
            id: 9,
            name: '赵六'
          },
          {
            id: 10,
            name: '田七'
          }
        ]
      })
    }, 3000)
  })
}

const pgTable = usePaginationTable({
  apiFun: getPaginationData
})

const columns = [
  {
    title: 'ID',
    dataIndex: 'id',
    width: 100
  },
  {
    title: '姓名',
    dataIndex: 'name',
    width: 400,
    align: 'center'
  }
]
</script>

<template>
  <div style="width: 500px">
    <a-table
      style="width: 100%"
      rowKey="id"
      :columns="columns"
      v-bind="pgTable.bindProps"
    ></a-table>
  </div>
</template>

<style lang="less" scoped></style>
<script setup lang="ts">
import { usePaginationTable } from '@hooks/components'

function getPaginationData() {
  return new Promise((resolve) => {
    setTimeout(() => {
      resolve({
        total: 10,
        current: 1,
        pageSize: 10,
        data: [
          {
            id: 1,
            name: '张三'
          },
          {
            id: 2,
            name: '李四'
          },
          {
            id: 3,
            name: '王五'
          },
          {
            id: 4,
            name: '赵六'
          },
          {
            id: 5,
            name: '田七'
          },
          {
            id: 6,
            name: '张三'
          },
          {
            id: 7,
            name: '李四'
          },
          {
            id: 8,
            name: '王五'
          },
          {
            id: 9,
            name: '赵六'
          },
          {
            id: 10,
            name: '田七'
          }
        ]
      })
    }, 3000)
  })
}

const pgTable = usePaginationTable({
  apiFun: getPaginationData
})

const columns = [
  {
    title: 'ID',
    dataIndex: 'id',
    width: 100
  },
  {
    title: '姓名',
    dataIndex: 'name',
    width: 400,
    align: 'center'
  }
]
</script>

<template>
  <div style="width: 500px">
    <a-table
      style="width: 100%"
      rowKey="id"
      :columns="columns"
      v-bind="pgTable.bindProps"
    ></a-table>
  </div>
</template>

<style lang="less" scoped></style>

参数

参数描述必选类型默认值
apiFun调用远程接口返回数据true()=>[]-
current初始页码false()=>any1
pageSize初始一页尺寸false(any)=>void10
queryInMount是否在挂载是调用接口初始化数据false(any)=>voidfalse
transformData接口数据转换false(data:any[])=>any[]-
getQueryParams获取参数回调false(page)=>any-

实例属性与方法

参数描述类型
bindProps绑定给组件的属性集合见下文
refresh刷新当前页面()=>promise
resetPage将表格的分页重置()=>promise
reload重置表格的分页,并刷新接口()=>promise
loading表格当前的加载状态boolean

bindProps

参数描述类型
loading控制按钮的loading状态boolean
pagination表格的分页数据{}
dataSource表格当前页数据any[]
onChange表格分页改变时的事件监听event