好几个业务页面都使用了scroll view里面的item也很很类似,所以想 自定义一个滚动scroll-view,把事件封装起来调用。
但是bindscroll事件怎么都没有执行。
基础库是:2.19.4
wxml
<view>
<scroll-view style="margin-top:{{nav_height}}px;height:{{windowH}}px"
bindscroll="scrollEvent" scroll-y="{{true}}" scroll-into-view="{{s_top}}"
scroll-with-animation bind:scrolltolower="{{orderlist.tolower}}">
<view>--</view>
<view>--</view>
<view>--</view>
<view>--</view>
<view>--</view>
<view>--</view>
<view>--</view>
<view>--</view>
<view>--</view>
</scroll-view>
</view>
JS
Component({
methods: {
scrollEvent(options) {
console.log(">>> 滚动视图,滚动了", options, this.data.windowH)
}
})
目前只能是把scroll-view放在父组件,自定义里面的item了,把item封装成组件。
解决:
过了几天又重新试了试,发现还是scroll-view的高度没有设置的原因。
直接在scroll view, style里写固定一个值: height:800px ,测试一下,能执行到scrollEvent里了。
<scroll-view style="margin-top:{{nav_height}}px;height:800px"
bindscroll="scrollEvent" scroll-y="{{true}}"
scroll-into-view="{{s_top}}"
enhanced scroll-with-animation>
<!--引用组件无法跳转到指定位置 scroll-into-view-->
<item list="{{list}}" id="s_top"></item>
</scroll-view>
<view class="end">没有更多数据~~</view>
<toTop isHidden="{{hiddenTopBtn}}" tapevent="tapevent"></toTop>