zoukankan      html  css  js  c++  java
  • scrol

    https://github.com/ankeetmaini/react-infinite-scroll-component

    import './alist.css';
    import {api} from '../common/axios'
    import React, { useState ,useEffect}  from 'react';
    import {HashRouter, Redirect ,Route, Switch,Link,useHistory } from 'react-router-dom';
    
    import InfiniteScroll from "react-infinite-scroll-component";
    
    
      function AirticleItem(props){
        let history = useHistory();
        function handClick(e){
          //alert(props.item.title)
          history.push("/article/"+props.item._id);
        }
        return (
              <div onClick={handClick} className="AirticleItem">
    
                  <div>   
                    <h5>{props.item.title}</h5>
                  </div>
    
                     <div dangerouslySetInnerHTML={{__html:props.item.content}}></div>
                  <div>
                    <span>{props.item.time}</span>
                    <span>{props.item.size}</span>
                    <span>{props.item.type}</span>
                  </div> 
              </div>
        );
      }
    
    let gSetMsg = null;
    let gMsg = null;
    let gList = [];
    async function getMsg(){
        if(gMsg>=1) return;
        //debugger;
        let ret = await api.get('/api/list?time='+new Date().getTime())
       // debugger;
        if(ret == undefined) return;
        console.log('---------------->')
        console.log(ret)
       
        //this.setState({data:ret.list})
        gList = ret
        console.log(gList)
    }
    
    
    class Mlist extends React.Component {
      state = {
        items: Array.from({ length: 0 })
      };
      componentDidMount() {
        this.fetchMoreData();
      }
      fetchMoreData = () => {
        // a fake async api call like which sends
        // 20 more records in 1.5 secs
    
        getMsg();
        setTimeout(() => {
          this.setState({
            items:this.state.items.concat(gList) //this.state.items.concat(Array.from({ length: 20 }))
          });
        }, 800);
      };
    
      render() {
        return (
          <div>
    
            <InfiniteScroll
              dataLength={this.state.items.length}
              next={this.fetchMoreData}
              hasMore={true}
              loader={<h4>加载中...</h4>}
            >
              {this.state.items.map((i, index) => (
                  <AirticleItem  item = {i}/> 
              ))}
            </InfiniteScroll>
          </div>
        );
      }
    }
    
    
    export default Mlist;
  • 相关阅读:
    GridView, ListView 区别
    ActivityGroup和TabActiviy的差异性?
    Java加密解压
    Android代码中实现WAP方式联网
    SVN创建资源库和远程连接配置
    高仿优酷Android客户端图片左右滑动(自动切换)
    andoid 多线程断点下载
    Android中用Java代码实现zip文件解压缩
    JAVA两种实现二分查找方式
    三种JAVA编程方法实现斐波那契数列
  • 原文地址:https://www.cnblogs.com/cnchengv/p/14891434.html
Copyright © 2011-2022 走看看