--- order: 6 title: zh-CN: 滚动加载 en-US: Scrolling loaded --- ## zh-CN 结合 [react-infinite-scroller](https://github.com/CassetteRocks/react-infinite-scroller) 实现滚动自动加载列表。 ## en-US The example of infinite load with [react-infinite-scroller](https://github.com/CassetteRocks/react-infinite-scroller). ```jsx import { List, message, Avatar, Spin } from 'antd'; import reqwest from 'reqwest'; import InfiniteScroll from 'react-infinite-scroller'; const fakeDataUrl = 'https://randomuser.me/api/?results=5&inc=name,gender,email,nat&noinfo'; class InfiniteListExample extends React.Component { state = { data: [], loading: false, hasMore: true, }; componentDidMount() { this.fetchData(res => { this.setState({ data: res.results, }); }); } fetchData = callback => { reqwest({ url: fakeDataUrl, type: 'json', method: 'get', contentType: 'application/json', success: res => { callback(res); }, }); }; handleInfiniteOnLoad = () => { let { data } = this.state; this.setState({ loading: true, }); if (data.length > 14) { message.warning('Infinite List loaded all'); this.setState({ hasMore: false, loading: false, }); return; } this.fetchData(res => { data = data.concat(res.results); this.setState({ data, loading: false, }); }); }; render() { return (
( } title={{item.name.last}} description={item.email} />
Content
)} > {this.state.loading && this.state.hasMore && (
)}
); } } ReactDOM.render(, mountNode); ``` ```css .demo-infinite-container { height: 300px; padding: 8px 24px; overflow: auto; border: 1px solid #e8e8e8; border-radius: 4px; } .demo-loading-container { position: absolute; bottom: 40px; width: 100%; text-align: center; } ```