本文實(shí)例為大家分享了上拉加載下拉刷新組件mescroll.js的具體代碼,供大家參考,具體內(nèi)容如下
附上鏈接地址http://www.mescroll.com/api.html#NPM,手機(jī)端和瀏覽器都能夠使用,唯一推薦;
使用過(guò)程中要注意這些問(wèn)題http://www.mescroll.com/qa.html;
使用注意事項(xiàng):
1、引入的時(shí)候出問(wèn)題及時(shí)看官方給出的解決方案(基本上都必須看);
2、react中一定要在dom渲染之后的方法(didMount)中初始化,因?yàn)檫@個(gè)需要拿到dom對(duì)象;
3、在react工程中,回調(diào)的數(shù)據(jù)一定要拼接,這是要注意的(datas:ctx.state.datas.concat(json.info));
4、很坑需要單頁(yè)的里的html和body高度設(shè)置100%。
下邊附上簡(jiǎn)易代碼
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 ( <div id="mescroll" className="mescroll" style={{height: "500px",overflow: "auto"}}> {this.state.datas.map((item,index)=>( <div key={index}> {item.id} </div> ))} </div> ); }} export default StretchingUp; 以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持武林網(wǎng)。
新聞熱點(diǎn)
疑難解答
圖片精選
網(wǎng)友關(guān)注