From 6a569084381cfc9fe9f0f02e16d21b7912ee48ef Mon Sep 17 00:00:00 2001 From: neverland Date: Sun, 6 Aug 2023 10:44:50 +0800 Subject: [PATCH] feat(List): add scroller prop (#12154) --- packages/vant/src/list/List.tsx | 8 ++++++-- packages/vant/src/list/README.md | 1 + packages/vant/src/list/README.zh-CN.md | 1 + 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/packages/vant/src/list/List.tsx b/packages/vant/src/list/List.tsx index e566b6827..49abda497 100644 --- a/packages/vant/src/list/List.tsx +++ b/packages/vant/src/list/List.tsx @@ -1,10 +1,12 @@ import { ref, watch, + computed, nextTick, onUpdated, onMounted, defineComponent, + type PropType, type ExtractPropTypes, } from 'vue'; @@ -36,6 +38,7 @@ export const listProps = { loading: Boolean, disabled: Boolean, finished: Boolean, + scroller: Object as PropType, errorText: String, direction: makeStringProp('down'), loadingText: String, @@ -59,6 +62,7 @@ export default defineComponent({ const placeholder = ref(); const tabStatus = useTabStatus(); const scrollParent = useScrollParent(root); + const scroller = computed(() => props.scroller || scrollParent.value); const check = () => { nextTick(() => { @@ -75,7 +79,7 @@ export default defineComponent({ const { direction } = props; const offset = +props.offset; - const scrollParentRect = useRect(scrollParent); + const scrollParentRect = useRect(scroller); if (!scrollParentRect.height || isHidden(root)) { return; @@ -170,7 +174,7 @@ export default defineComponent({ useExpose({ check }); useEventListener('scroll', check, { - target: scrollParent, + target: scroller, passive: true, }); diff --git a/packages/vant/src/list/README.md b/packages/vant/src/list/README.md index c77cbe118..893cd06c8 100644 --- a/packages/vant/src/list/README.md +++ b/packages/vant/src/list/README.md @@ -177,6 +177,7 @@ export default { | immediate-check | Whether to check loading position immediately after mounted | _boolean_ | `true` | | disabled | Whether to disable the load event | _boolean_ | `false` | | direction | Scroll direction, can be set to `up` | _string_ | `down` | +| scroller `v4.6.4` | Specifies the node that needs to listen for scroll events, defaults to the nearest parent scroll node | _Element_ | - | ### Events diff --git a/packages/vant/src/list/README.zh-CN.md b/packages/vant/src/list/README.zh-CN.md index e56f0e08e..6953e72db 100644 --- a/packages/vant/src/list/README.zh-CN.md +++ b/packages/vant/src/list/README.zh-CN.md @@ -192,6 +192,7 @@ export default { | immediate-check | 是否在初始化时立即执行滚动位置检查 | _boolean_ | `true` | | disabled | 是否禁用滚动加载 | _boolean_ | `false` | | direction | 滚动触发加载的方向,可选值为 `up` | _string_ | `down` | +| scroller `v4.6.4` | 指定需要监听滚动事件的节点,默认为最近的父级滚动节点 | _Element_ | - | ### Events