其实到了vue和react时代分页问题简化很多,这里重点讨论一种方式。
要实现的效果:
1.可传递总页数和显示页数,总页数超过显示页数中间要有省略号。
2.切换到省略显示页码时,要显示当前页面,左右边界页码随着变化,你可以设置当前页码左右显示的页数,改下判断逻辑就行。
3.当然要有上一页下一页和跳页。
total,limit为父组件传递的值
this.state = {
current: 1, //当前页
total: this.props.totalPage,
inputNum:'' //输入页码
}
render() {
return (
<div className="main">
<div className='page-container'>
<span className='total'>共{this.state.total}页</span>
<ul className="page">
{this.create.bind(this)()}
</ul>
<input className='jump' onChange={this.numChange.bind(this)} defaultValue={1}/>
<button className=' but