react 实现分页

编程入门 行业动态 更新时间:2024-10-21 03:37:37

react 实现<a href=https://www.elefans.com/category/jswz/34/1769545.html style=分页"/>

react 实现分页

一、在state里面定义 数据集 ,每页显示的第一个和最后一个

this.state = {//数据集datasetList: [],minValue:0,maxValue:44,};

二、跳转页面后你的第一个数据的id和最后一个数据的id ,这里每页显示10条数据

handleValue = value =>{
//value分页idconsole.log(value)
//分页小于等于1就是第一页没变if(value<=1){this.setState({minValue:0,maxValue:10,});}else {this.setState({minValue:(value-1)*10,maxValue:(value-1)*10+10});}
};

三、展示,下面是我展示图片是的代码片段(用map遍历,数据集使用slice(第一个id,最后一个id)来获取数据的)

 <Row >{this.state.datasetList.slice(this.state.minValue,this.state.maxValue).map(item =>(<Card.Gridstyle={gridStyle}><Image style={{width:"100px",minHeight:"100px",maxHeight:"100px"}}alt="example"src={item.fileUrl}/><p style={{width:"100px",minHeight:"20px",maxHeight:"20px"}}><Typography.Paragraphellipsis={{ tooltip: item.fileName }}style={{ marginBottom: '1px' }}>{item.fileName}</Typography.Paragraph></p> </Card.Grid>))}</Row><br/>

四、分页

 <Pagination 
//当前页数defaultCurrent={1} 
//每页条数defaultPageSize={10} 
//数据总数total={this.state.datasetList.length} onChange={this.handleValue} >
</Pagination>

这样就可以实现分页功能了。

更多推荐

react 实现分页

本文发布于:2024-03-05 04:08:57,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1711277.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:分页   react

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!