Skip to content

Commit

Permalink
fix(select): loading 配合触底事件 onScrollToBottom 一起使用的问题
Browse files Browse the repository at this point in the history
closed #4528
  • Loading branch information
lllllllqw committed Oct 10, 2024
1 parent a970a00 commit ca6eedc
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 13 deletions.
19 changes: 14 additions & 5 deletions src/select/_example-ts/scroll-bottom.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
<t-select
style="width: 300px"
:options="options"
:loading="loading"
placeholder="请选择"
:popup-props="{ onScrollToBottom: handleScrollToBottom }"
:popup-props="{ 'on-scroll-to-bottom': handleScrollToBottom }"
/>
</t-space>
</template>
Expand All @@ -31,11 +32,19 @@ for (let i = 1; i < 15; i++) {
// }
// };
const loading = ref(false);
// 直接使用滚动触底事件
const handleScrollToBottom = () => {
options.value = options.value.concat({
label: `滚动新增选项${options.value.length + 1}`,
value: options.value.length + 1,
});
if (loading.value) {
return;
}
loading.value = true;
setTimeout(() => {
options.value = options.value.concat({
label: `滚动新增选项${options.value.length + 1}`,
value: options.value.length + 1,
});
loading.value = false;
}, 500);
};
</script>
21 changes: 15 additions & 6 deletions src/select/_example/scroll-bottom.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
<t-select
style="width: 300px"
:options="options"
:loading="loading"
placeholder="请选择"
:popup-props="{ onScrollToBottom: handleScrollToBottom }"
:popup-props="{ 'on-scroll-to-bottom': handleScrollToBottom }"
/>
</t-space>
</template>
Expand All @@ -28,11 +29,19 @@ for (let i = 1; i < 15; i++) {
// }
// };
const loading = ref(false);
// 直接使用滚动触底事件
const handleScrollToBottom = () => {
options.value = options.value.concat({
label: `滚动新增选项${options.value.length + 1}`,
value: options.value.length + 1,
});
const handleScrollToBottom = async () => {
if (loading.value) {
return;
}
loading.value = true;
setTimeout(() => {
options.value = options.value.concat({
label: `滚动新增选项${options.value.length + 1}`,
value: options.value.length + 1,
});
loading.value = false;
}, 500);
};
</script>
6 changes: 4 additions & 2 deletions src/select/select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -284,11 +284,13 @@ export default defineComponent({
};

const handlerPopupScrollToBottom: PopupProps['onScrollToBottom'] = async (context) => {
const { onScrollToBottom } = (props.popupProps || {}) as TdSelectProps['popupProps'];
const { popupProps } = props;
if (props.loading) {
return;
}
onScrollToBottom?.(context);
// @ts-ignore types 中只有 onScrollToBottom,但 Vue 会自动转换 on-scroll-to-bottom 并支持,故此处都进行调用
popupProps?.['on-scroll-to-bottom']?.(context);
popupProps?.onScrollToBottom?.(context);
};

const addCache = (val: SelectValue) => {
Expand Down

0 comments on commit ca6eedc

Please sign in to comment.