Home >Web Front-end >JS Tutorial >Detailed explanation of mescroll.js pull-up loading pull-down refresh component
This article mainly introduces the use of the mescroll.js pull-up, load, and pull-down refresh components in detail. It has certain reference value. Interested friends can refer to it. I hope it can help everyone.
Precautions for use:
1. If there is a problem when introducing it, please check the official solution in time (basically you must read it);
2. In react, it must be initialized in the method (didMount) after dom rendering, because this requires getting the dom object;
3. In the react project, callback The data must be spliced, which should be noted (datas:ctx.state.datas.concat(json.info));
4. It is very tricky to need the html and body in a single page. The height is set to 100%.
A simple code is attached below
##
import React, { Component, PropTypes } from 'react'; import MeScroll from "mescroll.js" class StretchingUp extends Component { constructor(props, context) { super(props, context); this.state={ datas:[], total:0, } this.test = this.test.bind(this); } componentDidMount(){ document.ondragstart=function() {return false;} let ctx = this; var mescroll = new MeScroll ( "mescroll" , {down : { use:false}, up : { use:true, auto:true, offSet:100, page:{ num:0, size:20, time:null }, onScroll:function(mescroll, y, isUp){ }, callback:function (page, mescroll) { ctx.test(page, mescroll); }, error: function (e) { } }} ) ; mescroll.resetUpScroll() } test(page, mescroll){ console.log(page) let url = "http://localhost:5577/curpage/"+page.num+"/pagesize/"+page.size; let ctx = this; fetch(url,{ method:'GET', headers: { 'Accept': 'application/json', 'Content-Type': 'application/json', }, }).then((resp)=>{ if(resp){ return resp.json(); }else{ return false; } }) .then((json)=>{ ctx.setState({ datas:ctx.state.datas.concat(json.info), total:json.total },()=>{ }) mescroll.endSuccess(); return true; }); } render() { return ( <p id="mescroll" className="mescroll" style={{height: "500px",overflow: "auto"}}> {this.state.datas.map((item,index)=>( <p key={index}> {item.id} </p> ))} </p> ); }} export default StretchingUp;Related recommendations:
WeChat Mini Program development list pull-up loading pull-down refresh sample code
##dropload.js plug-in pull-down refresh and pull-up loading methodExample detailed explanation of mui pull-up Encapsulation process of loading more drop-down refresh dataThe above is the detailed content of Detailed explanation of mescroll.js pull-up loading pull-down refresh component. For more information, please follow other related articles on the PHP Chinese website!