export default class Home extends Component {
constructor(props) {
super(props);
this.wrapper = React.createRef();
}
async getOldMore(){
/*放你的请求地址*/
}
componentDidMount() {
let timeCount;
const that=this;
function callback() {
const top =that.wrapper.current.getBoundingClientRect().top;
const windowHeight = window.screen.height;
if (top && top < windowHeight) {
// 当 wrapper 已经被滚动到页面可视范围之内触发
that.getOldMore();
}
}
this.content.current.addEventListener('scroll', function () {
if (this.state.pagefinished) {
return ;
}
if (timeCount) {
clearTimeout(timeCount);
}
timeCount = setTimeout(callback, 50);
}.bind(this), false);
render() {
/*你之前的数据*/
<div className="loadMore" ref={this.wrapper} onClick={()=>this.getOldMore()}>加载更多</div>
}
}
研究研究就能用