//state:
hasMore: true,
page: 1,
listData: []
//方法
loadMore = async () => {
const { listData, page } = this.state;
const append = await this.getData(page + 1);
const addList = [...listData, ...append.appendList];
this.setState({
listData: addList,
hasMore: addList.length < append.total,
});
};
getData = async page => {
const res =await reqList({id:'3' });
if (res?.code === 200) {
const appendList = res.data;
return { appendList, total: res.data.total };
}
};
//render
const { hasMore } = this.state;
<InfiniteScroll loadMore={this.loadMore} hasMore={hasMore} />
antd-mobile下拉加载
于 2021-12-08 10:19:02 首次发布