您好,登錄后才能下訂單哦!
小編給大家分享一下MUI如何實(shí)現(xiàn)上拉刷新/下拉加載功能,相信大部分人都還不怎么了解,因此分享這篇文章給大家參考一下,希望大家閱讀完這篇文章后大有收獲,下面讓我們一起去了解一下吧!
新聞信息列表必備的功能,支持Table,Ul等列表.
以下是DIV版本,在安卓端或者ios端必須使用雙webview模式,傳送門:http://dev.dcloud.net.cn/mui/pulldown/
<!--下拉刷新容器--> <div id="pullrefresh" class="mui-content mui-scroll-wrapper"> <div class="mui-scroll"> <!--數(shù)據(jù)列表--> <ul class="mui-table-view"> </ul> </div> </div> <script type="text/javascript"> mui.init ({ pullRefresh: { container: '#pullrefresh', down: { callback: pulldownRefresh }, up: { contentrefresh: '正在加載...', callback: pullupRefresh } } }); /* * 下拉刷新具體業(yè)務(wù)實(shí)現(xiàn) */ function pulldownRefresh() { setTimeout(function() { var table = document.body.querySelector('.mui-table-view'); var cells = document.body.querySelectorAll('.mui-table-view-cell'); //模擬數(shù)據(jù) for (var i = cells.length, len = i + 3; i < len; i++) { var li = document.createElement('li'); li.className = 'mui-table-view-cell'; li.innerHTML = '<a class="mui-navigate-right">Item ' + (i + 1) + '</a>'; //下拉刷新,新紀(jì)錄插到最前面; table.insertBefore(li, table.firstChild); } mui('#pullrefresh').pullRefresh().endPulldownToRefresh(); //refresh completed }, 1500); } var count = 0; /* * 上拉加載具體業(yè)務(wù)實(shí)現(xiàn) */ function pullupRefresh() { setTimeout(function() { mui('#pullrefresh').pullRefresh().endPullupToRefresh((++count > 2)); //參數(shù)為true代表沒有更多數(shù)據(jù)了。 var table = document.body.querySelector('.mui-table-view'); var cells = document.body.querySelectorAll('.mui-table-view-cell'); for (var i = cells.length, len = i + 20; i < len; i++) { var li = document.createElement('li'); li.className = 'mui-table-view-cell'; li.innerHTML = '<a class="mui-navigate-right">Item ' + (i + 1) + '</a>'; table.appendChild(li); } }, 1500); } if (mui.os.plus) { mui.plusReady(function() { setTimeout(function() { mui('#pullrefresh').pullRefresh().pullupLoading(); }, 1000); }); } else { mui.ready(function() { mui('#pullrefresh').pullRefresh().pullupLoading(); }); } </script>
個(gè)人心得
1、手動(dòng)加載loading,并且會(huì)立即調(diào)用[下拉刷新]綁定的函數(shù)
mui('#pullrefresh').pullRefresh().pullupLoading(); //使用這個(gè)之后,自動(dòng)會(huì)加載[下拉刷新]綁定的函數(shù)
2、停止上拉刷新和下拉加載的loading
mui('#pullrefresh').pullRefresh().endPullupToRefresh(num >= cnt); //參數(shù)可以為返回true/false的表達(dá)式 mui('#pullrefresh').pullRefresh().endPulldownToRefresh();
3、初始化
初始化時(shí)通常要將原數(shù)據(jù)列表清空,如:$("#mui-table-view").html("");
那么請(qǐng)務(wù)必將以下代碼放置在清空代碼之后.這和scroll的滾動(dòng)性質(zhì)有關(guān)
mui('#pullrefresh').pullRefresh().refresh(true); //恢復(fù)滾動(dòng) mui('#pullrefresh').pullRefresh().scrollTo(0,0,100); //滾動(dòng)置頂
4、Iscroll方面的擴(kuò)展和內(nèi)容
https://www.jb51.net/article/111090.htm
5 Vue使用
<template> <div> <header class="mui-bar mui-bar-nav"> <button @click="model" class=" mui-btn mui-btn-blue mui-btn-link mui-btn-nav mui-pull-left"><span class="mui-icon mui-icon-left-nav"></span>{{ modelName }}</button> <h2 class="mui-title">笑話大全</h2> </header> <div class="mui-content mui-scroll-wrapper" id="pullrefresh" > <div class="mui-scroll"> <div class="mui-card" v-for="item in items"> <div class="mui-card-header mui-card-media" > <div class="mui-card-content-inner"> <p >{{ item.content }}</p> </div> </div> <div class="mui-card-content" v-if="item.url"> <img :src=" item.url " width="100%" height="100%" draggable="false"/> </div> <div class="mui-card-footer"> Posted on {{ item.updatetime }} </div> </div> </div> </div> </div> </template> <script> export default { data () { return { items:[], page :1, pagesize:5, count:0, modelName:"圖文" }; }, methods : { getJoke () { let self = this; var model = self.modelName == "圖文" ? "pic" : ""; $.ajax({ type:"get", url:`http://localhost:8090?${model}&page=${self.page}&pagesize=${self.pagesize}`, success (data) { let json = JSON.parse(data).result.data; self.items = self.items.concat(json); // 合并并且返回一個(gè)新數(shù)組 self.page += 1; self.count += 10; mui('#pullrefresh').pullRefresh().endPullupToRefresh(self.count >= 1000); } }) }, model () { this.modelName = this.modelName == "圖文" ? "文字" : "圖文"; this.items = []; this.getJoke(); }, pulldownRefresh () { setTimeout(() => { mui('#pullrefresh').pullRefresh().endPulldownToRefresh(); },1500) }, pullupRefresh () { this.getJoke(); } }, created () { let self = this; mui.ready(function(){ mui.init ({ pullRefresh: { container: '#pullrefresh', down: { callback: self.pulldownRefresh }, up: { contentrefresh: '正在加載...', callback: self.pullupRefresh } } }); self.getJoke(); }) } }; </script> <style lang="css" scoped> .mui-card:nth-last-child(1){margin-bottom:70px;} .mui-card-header>img:first-child{width:100%;height: 100%;} .mui-pull-bottom-pocket{position:inherit} </style>
以上是“MUI如何實(shí)現(xiàn)上拉刷新/下拉加載功能”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內(nèi)容對(duì)大家有所幫助,如果還想學(xué)習(xí)更多知識(shí),歡迎關(guān)注億速云行業(yè)資訊頻道!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。