react实现分页-封装组件

需求:根据后台的数据,判断是否有下一页。如果有下一页,用户上划加载更多调用接口。
结合 antd-mobileListView 组件实现。
参数解释

  1. dataSource:数据源(数组)
  2. currentPage:页数
  3. initialListSize:初始化展示的条数
  4. pageSize:每一页的条数
  5. onEndReachedThreshold:距离底部的距离
  6. nextLink:根据后台返回的数据,是否有下一页
  7. isLoadingMore:用户是否在上拉
  8. isRefreshing:用户是否在下拉
  9. damping:距离顶部多少进入下拉
import React from "react";
import {
    immutableRenderDecorator } from "react-immutable-render-mixin";
import PropTypes from "prop-types";
import {
    ListView } from "antd-mobile"
import {
    PullToRefresh } from "antd-mobile"

import "./refreshList-component.less";

class RefreshList extends React.Component {
   
    static defaultProps = {
   
        name: "stranger"
    }
    constructor(props) {
   
        super(props)
        const dataSource = new ListView.DataSource({
   
            rowHasChanged: (row1, row2) => row1 !== row2
        })
        this.state = {
   
            dataSource: dataSource.cloneWithRows(this.props.resLst), 
            currentPage: this.props.currentPage || 0, 
            initialListSize: this.props.initialListSize || 20, 
            pageSize: this.props.pageSize || 20, 
            onEndReachedThreshold: this.props.onEndReachedThreshold || 60, 
            nextLink: this.props.nextLink, 
            isLoadingMore: this.props.isLoadingMore || false, 
            isRefreshing: this.props.isRefreshing || false, 
            damping: this.props.damping || 26 
        };

    }
    componentWillReceiveProps(nextProps, nextState) {
   
        if (nextProps.resLst) {
   
            const dataSource = new ListView.DataSource({
   
                rowHasChanged: (row1, row2) => row1 !== row2
            })
            this.hasScroll = false
            this.setState({
   
                dataSource: dataSource.cloneWithRows(nextProps.resLst)
            }, 
  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值