mirror of
https://gitee.com/vant-contrib/vant-weapp.git
synced 2025-04-06 03:58:05 +08:00
29 lines
879 B
JavaScript
29 lines
879 B
JavaScript
function getCurrentPage() {
|
|
const pages = getCurrentPages();
|
|
return pages[pages.length - 1] || {};
|
|
}
|
|
function onPageScroll(event) {
|
|
const { vanPageScroller = [] } = getCurrentPage();
|
|
vanPageScroller.forEach((scroller) => {
|
|
if (typeof scroller === 'function') {
|
|
scroller(event);
|
|
}
|
|
});
|
|
}
|
|
export const pageScrollMixin = (scroller) => Behavior({
|
|
attached() {
|
|
const page = getCurrentPage();
|
|
if (Array.isArray(page.vanPageScroller)) {
|
|
page.vanPageScroller.push(scroller.bind(this));
|
|
}
|
|
else {
|
|
page.vanPageScroller = [page.onPageScroll, scroller.bind(this)];
|
|
}
|
|
page.onPageScroll = onPageScroll;
|
|
},
|
|
detached() {
|
|
const page = getCurrentPage();
|
|
page.vanPageScroller = (page.vanPageScroller || []).filter(item => item !== scroller);
|
|
}
|
|
});
|