mui框架实现上拉加载

如果你和我一样一点也没接触过mui框架,先看大神关于mui详解:
https://blog.csdn.net/qq_40147863/article/category/8079041

mui 有个开发文档预览式 app,下载Hello mui App http://dcloud.io/hellomui/
官方下拉刷新:http://dev.dcloud.net.cn/mui/pulldown/
官方上拉加载:http://dev.dcloud.net.cn/mui/pullup/

官方上拉加载源码如下:https://github.com/dcloudio/mui/blob/master/examples/hello-mui/examples/pullrefresh.html

中国国内 - 可用API合集
https://blog.csdn.net/qq_40147863/article/details/82855787

<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<title>Hello MUI</title>
		<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">

		<link rel="stylesheet" href="../css/mui.min.css">
		<style type="text/css">
			.mui-content>.mui-table-view:first-child {
				margin-top: -1px;
			}
		</style>
	</head>

	<body>
		<!--下拉刷新容器-->
		<div id="pullrefresh" class="mui-content mui-scroll-wrapper">
			<div class="mui-scroll">
				<!--数据列表-->
				<ul class="mui-table-view mui-table-view-chevron"></ul>
			</div>
		</div>
		<script src="../js/mui.min.js" type="text/javascript" charset="utf-8"></script>
		<script>
			
			mui.init({
				pullRefresh: {
					container: '#pullrefresh',
					down: {
						style:'circle',
						callback: pulldownRefresh
					},
					up: {
						auto:true,
						contentrefresh: '正在加载...',
						callback: pullupRefresh
					}
				}
			});
			
			var count = 0;
			function pullupRefresh() {
				setTimeout(function() {
					mui('#pullrefresh').pullRefresh().endPullupToRefresh((++count > 2)); //参数为true代表没有更多数据了。
					var table = document.body.querySelector('.mui-table-view');
					var cells = document.body.querySelectorAll('.mui-table-view-cell');
					var newCount = cells.length>0?5:20;//首次加载20条,满屏
					for (var i = cells.length, len = i + newCount; 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);
			}
			function addData() {
				var table = document.body.querySelector('.mui-table-view');
				var cells = document.body.querySelectorAll('.mui-table-view-cell');
				for(var i = cells.length, len = i + 5; 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.insertBefore(li, table.firstChild);
				}
			}
			/**
			 * 下拉刷新具体业务实现
			 */
			function pulldownRefresh() {
				setTimeout(function() {
					addData();
					mui('#pullrefresh').pullRefresh().endPulldownToRefresh();
					mui.toast("为你推荐了5篇文章");
				}, 1500);
			}
		</script>
	</body>

</html>

mui 结合 vue.js 处理数据(下拉刷新,上拉加载)
https://blog.csdn.net/Young_Gao/article/details/83825611

https://blog.csdn.net/Young_Gao/article/details/83825611

mui中上拉刷新事件a标签中的链接、元素onclick事件在手机上点击不了
https://blog.csdn.net/abs1004/article/details/78112630

MUI移动端页面跳转
https://blog.csdn.net/xuepan1994/article/details/51900447

mui 上拉加载 实现分页加载功能
https://www.cnblogs.com/vicky123/p/9075718.html

mui('#newsSports').on('tap', 'li', function() { //给li添加点击事件,直接写普通的a标签或者在元素上加onclick事件不成功
				                                    alert("---33----");
													location.href = "news_detail.html";
				                                });
mui.init(
            {
                pullRefresh : {
                    container:"#refreshContainer",
                    down: {
                		  contentdown : "下拉刷新",//可选,在下拉可刷新状态时,下拉刷新控件上显示的标题内容
                    	  contentover : "释放立即刷新",//可选,在释放可刷新状态时,下拉刷新控件上显示的标题内容
                   		  contentrefresh : "正在刷新...",//可选,正在刷新状态时,下拉刷新控件上显示的标题内容
		             	  style:'circle',//必选,下拉刷新样式,目前支持原生5+ ‘circle’ 样式
			              color:'#2BD009', //可选,默认“#2BD009” 下拉刷新控件颜色
			              height:'50px',//可选,默认50px.下拉刷新控件的高度,
			              range:'100px', //可选 默认100px,控件可下拉拖拽的范围
			              offset:'0px', //可选 默认0px,下拉刷新控件的起始位置
			              auto: true,//可选,默认false.首次加载自动上拉刷新一次
                          auto: true,
                          callback: pulltofresh
                    },
                    up: {                        
						height:50,//可选.默认50.触发上拉加载拖动距离
                        auto:true,//可选,默认false.自动上拉加载一次
                        contentrefresh : "正在加载...",//可选,正在加载状态时,上拉加载控件上显示的标题内容
                        contentnomore:'没有更多数据了',//可选,请求完毕若没有更多数据时显示的提醒内容;
                        callback: pushtoloadmore
                    }
                }
            }
        )
        function pulltofresh() {
           app.page = 1;
            mui.ajax(adminUrl + 'common/newsServer/1?rows=10&page=' + app.page, {
                type: 'get',
                success: function(res){
                   app.sports = res.data;
					console.log(res.data)
                },
                error: function(e) {
                    
                }
            })
            mui('#refreshContainer').pullRefresh().endPulldownToRefresh();

			mui('#newsSports').on('tap', '.mui-table-view-cell', function() { //给li添加点击事件,直接写普通的a标签或者在元素上加onclick事件不成功
				                                    mui.openWindow({  
														url: "news_detail.html"  
													})  													
				                                });

        }
        function pushtoloadmore() {
            app.page++;
            mui.ajax(adminUrl + 'common/newsServer/1?rows=10&page=' + app.page, {
                type: 'get',
                success: function(res){
                   app.sports = app.sports.concat(res.data.data);
                },
                error: function(e) {
                    
                }
            })
            mui('#refreshContainer').pullRefresh().endPullupToRefresh();
        }

猜你喜欢

转载自blog.csdn.net/fengtingYan/article/details/85617720