uniapp scroll-view滑到底部加载更多数据

官网

必须设置下面两个属性

1. scroll-y="true" 

2. height:90vh;

    //lowerBottom触底事件
<scroll-view @scrolltolower="lowerBottom" style="height:90vh;" scroll-y="true">
   //list:展示的数据
    <view class="list" v-for="(item,index) in list" :key="index" >
        {{item.content}}
    </view>	
    //bottomText底部文字
	<view class="medicine_title">
		{isBottom?'没有更多数据了~':'下拉加载更多'}}
	</view>
</scroll-view>

data数据

list:[],   //展示的数据
//分页参数,跟后台协商参数
listQuery:{
    page:1,
    size:10,
},
//判断是否请求完毕数据
isBottom: false,

进入页面加载完请求第一页数据(onLoad)或者切入前台请求(onShow),根据需求修改,我这里是onLoad

onLoad(options) {

    this.listInit()
},
methods:{
    listInit(){
		this.listQuery.page = 1
		this.list = []
		this.isBottom = false
		this.getList()
	},
    async getList(val) {
		let query = this.listQuery
        //请求数据 ,此为封装后的请求接口方法
		let list = await this.$request(‘接口地址’, 'get', query)
		this.list = this.list.concat(list.data.item)
        //判断是否请求完毕
		if (list.data.item.length < this.listQuery.size) {
			this.isBottom = true
		}
	},
    // 滚到底部
	lowerBottom() {
		if (!this.isBottom) {
			this.listQuery.page += 1
			this.getList()
		}
	},
}

  • 3
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要使用uni-app实现scroll-view的分页功能,可以按照以下步骤进行操作: 1. 在uni-app的页面中,使用scroll-view组件包裹需要滚动的内容。 2. 添加一个变量来记录当前显示的页数,例如currentPage。 3. 使用scroll-view的bindscrolltoupper和bindscrolltolower事件来监听滚动到顶部和底部的动作。 4. 在bindscrolltoupper事件中,将currentPage减1,并更新页面显示的内容。 5. 在bindscrolltolower事件中,将currentPage加1,并更新页面显示的内容。 6. 在页面中使用条件渲染,根据currentPage的值来显示不同的内容。 下面是一个示例代码: ```html <template> <view> <scroll-view scroll-y @scrolltoupper="onScrollToUpper" @scrolltolower="onScrollToLower" > <!-- 显示第一页内容 --> <view v-if="currentPage === 0"> <!-- 第一页内容 --> </view> <!-- 显示第二页内容 --> <view v-if="currentPage === 1"> <!-- 第二页内容 --> </view> <!-- 显示第三页内容 --> <view v-if="currentPage === 2"> <!-- 第三页内容 --> </view> <!-- ... 其他页的内容 --> </scroll-view> </view> </template> <script> export default { data() { return { currentPage: 0 }; }, methods: { onScrollToUpper() { if (this.currentPage > 0) { this.currentPage--; // 更新页面显示的内容 } }, onScrollToLower() { this.currentPage++; // 更新页面显示的内容 } } }; </script> ``` 在上述示例代码中,我们使用了scroll-view组件来实现滚动效果,并通过条件渲染来显示不同页的内容。在滚动到顶部时,会触发onScrollToUpper方法,将currentPage减1,并更新页面显示的内容;在滚动到底部时,会触发onScrollToLower方法,将currentPage加1,并更新页面显示的内容。通过这种方式,就可以实现scroll-view的分页功能。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值