安装
"@better-scroll/core": "^2.2.1",
"@better-scroll/pull-up": "^2.2.1",
引入
哪里使用就在哪引入
import BScroll from "@better-scroll/core";
import Pullup from "@better-scroll/pull-up";
BScroll.use(Pullup);
代码
var scroll: any;
onMounted(() => {
initBscroll();
})
const initBscroll = () => {
// 初始化滚动
scroll= new BScroll(".wrapper", {
scrollY: true,
// 上拉距离超过50px时触发 pullingUp 事件
pullUpLoad: {
threshold: -50,
},
});
scroll.on("pullingUp", () => {
getData();
});
}
// 请求数据
const getData = () => {
console.log(123);
// 告诉bs准备下一次的pullingUp钩子
scroll.finishPullUp();
}
后续功能再研究。