antd-mobile上拉加载组件 分离


```javascript
/**
 * @description: 上拉加载组件
 * @param {*} 传入 row(循环的每一行数据) getData() 请求数据   dataList 数据源
 * @return {*}
 */
 import React from 'react'

 import { ListView } from 'antd-mobile';
 
 class ListContainer extends React.Component {
   constructor(props) {
     super(props);
     const dataSource = new ListView.DataSource({  //这个dataSource有cloneWithRows方法
       rowHasChanged: (row1, row2) => row1 !== row2,
     });   
     
     this.state = {
       dataSource,
       isLoading: true,
       hasMore: true
     };
   }
   
   componentWillReceiveProps(nextProps) {
     this.setState({
       dataSource: this.state.dataSource.cloneWithRows(nextProps.dataList),
       refreshing: false,
       isLoading: false,
     });
    }
 
 
   onEndReached =  () => {
     if(this.props.dataList.length < 9) {
       this.setState({
         hasMore: false
       })
     }else {
       this.props.getData()
     }
   };
 
   render() {
     return (
       <div>
         <ListView
           ref={el => this.lv = el}
           dataSource={this.state.dataSource}
           renderFooter={    //renderFooter就是下拉时候的loading效果,这里的内容可以自己随需求更改
             () => (
                   <div style={{  textAlign: 'center' }}>
                     {this.state.isLoading ? '加载中...' : '暂无数据'}
                   </div>
                 )
           }
           renderRow={this.props.row}   //渲染你上边写好的那个row
           style={{
             minHeight: 'calc(100vh - 100px)',
             border: '1px solid #ddd',
             margin: '5px 0',
           }}
           onEndReached={this.onEndReached}
           pageSize={10}    //每次下拉之后显示的数据条数
         />
       </div>
     );
   }
 }
 
 export default ListContainer



## 用法

```javascript
 import ListContainer from '../../components/ListView'
// 应用
	<List>
		{this.state.data  && <ListContainer dataList={this.state.data} row={row} getData={this.getData} /> } 
 	</List>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值