• 下拉加载更多数据


    <!DOCTYPE html>
    <html lang="zh">
    	<head>
    		<meta charset="UTF-8" />
    		<meta name="viewport" content="width=device-width, initial-scale=1.0" />
    		<meta http-equiv="X-UA-Compatible" content="ie=edge" />
    		<title>下拉加载更多</title>
    		<style>
    			* {
    				padding: 0;
    				margin: 0;
    			}
    			.box{
    				 100%;
    				height: 360px;
    				line-height: 360px;
    				text-align: center;
    				font-size: 26px;
    				font-weight: bold;
    			}
    			.listData{
    				 90%;
    				height: 40px;
    				line-height: 40px;
    				text-align: center;
    				border: 1px dashed red;
    				margin: 0 auto;
    				margin-top: 10px;
    				overflow: hidden;
    				white-space: nowrap;
    				text-overflow: ellipsis;
    				margin-bottom: 30px;
    			}
    			.loadings{
    				 100%;
    				height: 40px;
    				text-align: center;
    				line-height: 40px;
    				background: skyblue;
    			}
    		</style>
    	</head>
    
    	<body>
    		<div id="app">
    			<div class="box">这是一个标题</div>
    			<div class="box"></div>
    			<p class="listData" v-for="item in arr"> <a href="https://baidu.com">{{ item.title }}</a> </p>
    			<p class="loadings" v-if="loads">正在加载。。。。</p>
    		</div>
    		<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
    		<script src="https://cdn.bootcss.com/axios/0.19.0-beta.1/axios.min.js"></script>
    		<script>
    			var vm = new Vue({
    				el: '#app',
    				data: {
    					arr: [],		//需要循环的数据
    					scrolls: false, //用于判断是否触底
    					page: 3,		//定义传入的page
    					loads:false	//是否显示加载标签
    				},
    				methods: {
    					scroll() {
    						var scrollTop = document.body.scrollTop || document.documentElement.scrollTop;
    						var client = document.documentElement.clientHeight;
    						var overall = document.body.clientHeight;
    						//在距离底部 30px 位置的时候就进行调用接口(可按需调动)
    						if(scrollTop + client >= (overall - 30) && this.scrolls) {
    							this.scrolls = false;
    							this.page++;
    							this.page <= 10 && this.ajaxdata()
    							if(this.page >= 10){
    								this.loads = false
    							}else{
    								this.loads = true;
    							}
    						}
    					},
    					//请求数据
    					async ajaxdata() {
    						//接口处理
    						const {data} = await axios.post('https://bj.qhtest.site/byzz/v1.home/analysis', {page: this.page})
    						var listdata = data.data.list[0].value;
    						if(data.code == 200) {
    							this.scrolls = true;
    							this.loads = false;
    							this.arr = this.arr.concat(data.data.list[0].value);
    						}
    					}
    				},
    				created() {
    					this.ajaxdata();
    				},
    				mounted() {
    					window.addEventListener('scroll', this.scroll)
    				}
    			})
    		</script>
    	</body>
    
    </html>
    
  • 相关阅读:
    ML(5)——神经网络1(神经元模型与激活函数)
    ML(4)——逻辑回归
    ML(附录3)——过拟合与欠拟合
    多变量微积分笔记24——空间线积分
    iOS开发--横向流水布局实现
    李洪强和你一起学习前端之面试题
    前端面试题 -- JS篇
    很强大的HTML+CSS+JS面试题(附带答案)
    李洪强iOS之集成极光推送三iOS集成指南
    李洪强iOS之集成极光推送二iOS 证书 设置指南
  • 原文地址:https://www.cnblogs.com/a-pupil/p/10796221.html
Copyright © 2020-2023  润新知