uniapp中scroll-view的scrolltolower事件不触发

uniapp中scroll-view的scrolltolower事件不触发

有两种情况

第一种情况
scroll-view中的订单列表详情没有用一个view包起来

<view class="navbar">
	<view v-for="(item, index) in navList" :key="index" class="nav-item" :class="{current: tabCurrent == item.type}"
@click="tabClick(item.type)">
	{{item.text}}
	</view>
</view>
<view class="orderCon">
	<scroll-view class="list-scroll-content" :style="'height:' + scrollHeight + 'px'" scroll-y @scrolltolower="bindDownLoad">
		<!-- 订单列表 -->
		<view v-for="(item, index) in orderList" :key="index" class="order-item">
		...
		</view>
		<view v-if="no_more" class="no-more">, 没有更多了
		</view>
		<!-- 无数据提供的页面 -->
		<view v-if="!orderList.length">
			<view class="yoshop-notcont">
				<text class="cont">亲,暂无订单哦</text>
			</view>
		</view>
	</scroll-view>
</view>

这里面order-item每个订单详情之间用margin-top隔一定距离
如果order-item里面不写margin-top
1、如果页面的订单列表的height(所有order-item的height)没有超过页面的height(scroll-view的height),将无法去触发scrolltolower事件
2、如果订单列表的height(所有order-item的height)超过页面的height(scroll-view的height),可以触发scrolltolower事件

.orderCon {
// 不要用margin-top也不要写height: 100%
	padding-top: 80upx;
}
.order-item {
	display: flex;
	flex-direction: column;
	background: #fff;
	margin-top: 16upx;
}

第二种情况
scroll-view中的订单列表详情用一个view(class=“orderList”)包起来

<view class="navbar">
	<view v-for="(item, index) in navList" :key="index" class="nav-item" :class="{current: tabCurrent == item.type}" @click="tabClick(item.type)">
		{{item.text}}
	</view>
</view>
<view class="orderCon">
	<scroll-view class="list-scroll-content" :style="'height:' + scrollHeight + 'px'" scroll-y @scrolltolower="bindDownLoad">
		<!-- 订单列表 -->
		<view class="orderList">
			<view v-for="(item,index) in orderList" :key="index" class="order-item" @click="goOrderDetail(item.orderId)">
			...
			</view>
		</view>
		<view v-if="no_more" class="no-more">, 没有更多了
		</view>
		<!-- 无数据提供的页面 -->
		<view v-if="!orderList.length">
			<view class="yoshop-notcont">
				<text class="cont">亲,暂无订单哦</text>
			</view>
		</view>
	</scroll-view>
</view>

解决方法有两种
1、这里面order-item每个订单详情之间用margin-top隔一定距离(不写或写padding-top订单列表的height(所有order-item的height)没有超过页面的height(scroll-view的height)不会触发scrolltolower事件)
2、如果order-item没有用margin-top,可以在订单列表最大的view(class=“orderList”)写margin-top(也可以写padding-top(也可以都不写),区别在于写padding-top(都不写),订单列表的height(所有order-item的height)没有超过页面的height(scroll-view的height)不会触发scrolltolower事件,写margin-top会触发scrolltolower事件)

.orderCon {
// 不要用margin-top也不要写height: 100%
	padding-top: 80upx;
}
.order-item {
	display: flex;
	flex-direction: column;
	background: #fff;
	margin-top: 16upx;
}
  • 8
    点赞
  • 17
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
UniAppscroll-view组件是用于实现可滚动区域的容器。它可以在垂直方向上或水平方向上滚动内容,并可以设置滚动条的样式和行为。 使用scroll-view组件时,可以通过设置不同的属性来控制滚动视图的行为和样式。常用的属性包括: - scroll-x:是否横向滚动,默认为false。 - scroll-y:是否纵向滚动,默认为true。 - upper-threshold:距顶部/左边多远时(单位px),触发 scrolltoupper 事件,默认为50。 - lower-threshold:距底部/右边多远时(单位px),触发 scrolltolower 事件,默认为50。 - scroll-top:设置初始滚动位置,单位px。 - scroll-left:设置初始横向滚动位置,单位px。 - scroll-into-view:设置滚动到的目标元素id。 - scroll-with-animation:是否使用动画过渡,默认为false。 - bindscrolltoupper:滚动到顶部/左边时触发事件。 - bindscrolltolower:滚动到底部/右边时触发事件。 除了以上属性外,还可以通过slot插槽来自定义scroll-view的内容。 使用示例: ```html <scroll-view class="container" scroll-y bindscrolltoupper="onScrollToUpper" bindscrolltolower="onScrollToLower"> <view class="item" wx:for="{{list}}">{{item}}</view> </scroll-view> ``` ```javascript export default { data() { return { list: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] } }, methods: { onScrollToUpper() { console.log('滚动到顶部了') }, onScrollToLower() { console.log('滚动到底部了') } } } ``` 在上述示例scroll-view组件包裹了一个view组件作为内容,并通过wx:for循环渲染了一个列表。通过设置scroll-y属性为true,可以在纵向方向上滚动内容。同时,绑定了scrolltoupper和scrolltolower事件,当滚动到顶部或底部时触发相应的事件回调函数。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值