fix: virtual-list height reactive (#3972)

pull/4001/head
zkwolf 2021-04-25 13:22:10 +08:00 committed by GitHub
parent 7851c77db3
commit 184f6cac2f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 5 deletions

View File

@ -134,10 +134,11 @@ const List = defineComponent({
// ================================ Height ================================
const [setInstance, collectHeight, heights] = useHeights(getKey, null, null);
// ========================== Visible Calculation =========================
const calRes = computed(() => {
const calRes = ref();
watchEffect(() => {
if (!useVirtual.value) {
return {
calRes.value = {
scrollHeight: undefined,
start: 0,
end: state.mergedData.length - 1,
@ -147,7 +148,7 @@ const List = defineComponent({
// Always use virtual scroll bar in avoid shaking
if (!inVirtual.value) {
return {
calRes.value = {
scrollHeight: fillerInnerRef.value?.offsetHeight || 0,
start: 0,
end: state.mergedData.length - 1,
@ -193,13 +194,14 @@ const List = defineComponent({
// Give cache to improve scroll experience
endIndex = Math.min(endIndex + 1, state.mergedData.length);
return {
calRes.value = {
scrollHeight: itemTop,
start: startIndex,
end: endIndex,
offset: startOffset,
};
});
// =============================== In Range ===============================
const maxScrollHeight = computed(() => calRes.value.scrollHeight! - props.height!);