使用Sticky
粘性布局的时候,调用@scroll
<van-sticky @scroll="scrollHandle">
<van-button type="primary">基础用法</van-button>
</van-sticky>
scroll
的回调参数为{ scrollTop
: 距离顶部位置, isFixed
: 是否吸顶 }
scrollHandle(data){
console.log(`回调参数`,data) // {scrollTop:0,isFixed:true}
}
需求
<van-sticky @scroll="scrollHandle(`123`)">
<van-button type="primary">基础用法</van-button>
</van-sticky>
只要以scrollHandle()
或者传自定义参数,就会覆盖默认的回调参数
scrollHandle(data){
console.log(`回调参数`,data) // 123
}
实现
在传参的末尾,添加$event
参数即可
<van-sticky @scroll="scrollHandle(`123`,$event)">
<van-button type="primary">基础用法</van-button>
</van-sticky>
结果
scrollHandle(item,data){
console.log(`回调参数`,item,data) // 123 ,{scrollTop:0,isFixed:true}
}
总结