uni-app scroll-view特定情况下运用

javascript 复制代码
//下拉刷新,需要自己在page.json文件中配置开启页面下拉刷新 "enablePullDownRefresh": true
onPullDownRefresh:function() {
    setTimeout(()=>{
		this.param.page = 1;
		this.totalPage = 0;
		this.list=[];
		this.getlist();
        uni.stopPullDownRefresh();
    }, 1000);
},
javascript 复制代码
//上拉加载,需要自己在page.json文件中配置"onReachBottomDistance"
onReachBottom:function(){
	if(this.param.page>= this.totalPage){
		this.status = 'noMore';
		return false;
	}else{
		this.status = 'loading';
	}
	this.param.page += 1;
	this.getlist();
},

如果page中css样式设置了height:100%后, 页面的上拉 下拉就不生效了,有时又需要设置高度100% 来构建页面样式,这种情况下就得运用 scroll-view 来分页数据了

javascript 复制代码
<scroll-view ref="add" :scroll-y="true" style="flex: 1;overflow-y: auto;" class="order-list" @scrolltolower="scrollView">
scrollView() {
	// 数据加载到与总数量一样
	if (this.list.length == this.total) {
		uni.showToast({
			title: '翻到底了!',
			icon: "none"
		});
		return false
	}
	uni.showLoading({
		mask: true,
		title: "加载中"
	})
	setTimeout(() => {
		uni.hideLoading()
		this.param.page++;
		this.getlist();
	}, 500)
},
javascript 复制代码
getlist:function(){
	this.isLoading = true;
	this.majax({url:this.$local + 'pos/book/restock/page', params:this.param,method:'POST'}).then(res => {
		this.isLoading = false;
		if(res.code === 0){
			let mlist = res.data.records.map(item => {
				item.flag = false
				item.sl = item.ygbsl
				return {...item}
			});
			this.total = res.data.total
			this.totalPage = res.data.pages;
		  for (let i = 0; i < mlist.length; i++) {
			this.list.push(mlist[i])
		  }
		}else{
		  this.goout(res);
		}
    });
},
相关推荐
brucelee18614 分钟前
OpenClaw 浏览器控制(Chrome MCP)完整教程
前端·chrome
ct97828 分钟前
React 状态管理方案深度对比
开发语言·前端·react
胡志辉的博客1 小时前
深入浅出理解浏览器事件循环:从一道输出题讲到 Chrome 源码
前端·javascript·chrome·chromium·event loop
代码不加糖1 小时前
js中不会冒泡的事件有哪些?
前端·javascript·vue.js
懂懂tty1 小时前
Vue2与Vue3之间API差异
前端·javascript·vue.js
AI焦点1 小时前
跨越协议鸿沟:Tool Use状态机从Anthropic到OpenAI兼容体系的适配要点
前端·人工智能
Dxy12393102161 小时前
Python线程锁:为什么多线程会“打架“,以及怎么解决
开发语言·前端·python
海兰2 小时前
【web应用】Excel 项目数据自动化分析系统(AI 驱动分析)详细设计与部署指南(附源代码)
前端·人工智能·自动化·excel
小二·2 小时前
Next.js 15 全栈开发实战
开发语言·javascript·ecmascript
2501_940041742 小时前
技术分享:高质量全栈开发提示词设计实践 —— 覆盖简单到复杂
前端·prompt