Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Need Help] 关于 usePagination的疑问 #240

Closed
like0413 opened this issue Jun 23, 2024 · 5 comments
Closed

[Need Help] 关于 usePagination的疑问 #240

like0413 opened this issue Jun 23, 2024 · 5 comments
Labels
question Further information is requested

Comments

@like0413
Copy link

问题描述 Problem Description

我按照ant design 的示例:

<script lang="ts" setup>
import type { TableProps } from 'ant-design-vue'
import { getDemoTable } from '@/api/demo'

const columns = []

const {
  data,
  run,
  loading,
  current,
  pageSize,
  total
} = usePagination(getDemoTable, {
  pagination: {
    currentKey: 'ext.page',
    pageSizeKey: 'ext.size',
    totalKey: 'ext.total',
  },
})
const dataSource = computed(() => data.value?.list ?? [])

const pagination = computed(() => ({
  total: total.value,
  current: current.value,
  pageSize: pageSize.value,
}))

const onTableChange: TableProps['onChange'] = (pag, filters, sorter) => {
  run({
    page: pag.current,
    size: pag.pageSize,
    sorter: sorter,
    ...filters,
  })
}
</script>

<template>
  <a-table
    :row-key="(record) => record.id"
    :columns="columns"
    :data-source="dataSource"
    :pagination="pagination"
    :loading="loading"
    @change="onTableChange"
  ></a-table>
</template>

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

这是接口的返回结构:
image

我的疑惑:
初次时参数是这样的:
image
点击分页时是这样的:
image

我不太理解初次的传参为什么是这样

其他信息 Other information

@like0413 like0413 added the question Further information is requested label Jun 23, 2024
@John60676
Copy link
Member

currentKeypageSizeKey 在你这个例子中应该填的是 'page' 和 'size',它们是 getDemoTable 请求函数的形参名

@like0413
Copy link
Author

currentKeypageSizeKey 在你这个例子中应该填的是 'page' 和 'size',它们是 getDemoTable 请求函数的形参名

如果填 'page' 和 'size',就不匹配我的返回值了,值是在ext里的

@John60676
Copy link
Member

匹配的是接口的入参,不是返回值

@shaoerkuai
Copy link

currentKey 和 pageSizeKey 是入参,返回值是totalKey和totalPageKey。
如果你放ext,应该是totalKey = data.data.ext.total totalPageKey以此类推。
pageno 和 size,不需要从你的接口返回去读的,这个是用的请求的参数+返回的total来进行计算的,确保分页能访问到响应体ext.total的字段即可。

@like0413
Copy link
Author

感谢。文档我没看仔细,也是没想到pagination既有入参也有返回值

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants