简体   繁体   English

如何添加antd分页组件?

[英]How to add antd pagination component?

I want to add Antd Pagination ( documentation ) to project in "ArticlesList" component, but have no idea yet - what should I pass to pagination component to onChange = {????} Tried to make different variants, but its not work.我想将 Antd 分页(文档)添加到“ArticlesList”组件中的项目,但还不知道 - 我应该将什么传递给分页组件onChange = {????}尝试制作不同的变体,但它不起作用。 Any help or advice how to do it?任何帮助或建议如何做到这一点?

You can see code here: codesandbox你可以在这里看到代码: codesandbox

You should pass your total articles length, current page and onChnage function gets two params which is page number and page size which number of articles you want to show in a page or component.您应该传递您的总文章长度、当前页面和 onChnage 函数获取两个参数,即页码和页面大小,即您希望在页面或组件中显示的文章数量。

by onChange you fetch your next list.通过 onChange 你获取你的下一个列表。

const onChange = (page, pageSize) => {
  fetch(`yourApi/page=${page}&pageSize=${pageSize})
}

<Pagination
  total={totalArticles}
  current={currentPage}
  onChange={(page, pageSize) => onChange(page, pageSize)}
/>

mock data:模拟数据:

{
  articles: [],
  totalArticles: 60,
  page: 1,
  pageSize: 10, // Its up to you
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM