React 滚动到底部加载数据


 

function DataInfo() {    
    const [dom, setDom] = useState(HTMLDivElement | null);
    const [logData, setLogData] = useState('');
   
     // 获取数据的方法
    function getLogPages () {
        ...
    }

    // 监听页面滚动
    const handleOnScroll = () => {
        if (dom) {
            const contentScrollTop = dom.scrollTop; //滚动条距离顶部
            const clientHeight = dom.clientHeight; //可视区域
            const scrollHeight = dom.scrollHeight; //滚动条内容的总高度
            if (contentScrollTop + clientHeight >= scrollHeight) {
                getLogPages();    // 获取数据的方法
            }
        }
    };
    return (
     <div  className="modal-body logHeight"
          style={{ height: '480px' }}
          ref={(dom) => {
                    setDom(dom);
                }}
           onScrollCapture={() => handleOnScroll()}
           >
           {logData}
    </div>    
  )
}

 

 

 




					


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM