Skip to content

Commit 184f6ca

Browse files
authored
fix: virtual-list height reactive (#3972)
1 parent 7851c77 commit 184f6ca

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

components/vc-virtual-list/List.tsx

+7-5
Original file line numberDiff line numberDiff line change
@@ -134,10 +134,11 @@ const List = defineComponent({
134134

135135
// ================================ Height ================================
136136
const [setInstance, collectHeight, heights] = useHeights(getKey, null, null);
137-
// ========================== Visible Calculation =========================
138-
const calRes = computed(() => {
137+
138+
const calRes = ref();
139+
watchEffect(() => {
139140
if (!useVirtual.value) {
140-
return {
141+
calRes.value = {
141142
scrollHeight: undefined,
142143
start: 0,
143144
end: state.mergedData.length - 1,
@@ -147,7 +148,7 @@ const List = defineComponent({
147148

148149
// Always use virtual scroll bar in avoid shaking
149150
if (!inVirtual.value) {
150-
return {
151+
calRes.value = {
151152
scrollHeight: fillerInnerRef.value?.offsetHeight || 0,
152153
start: 0,
153154
end: state.mergedData.length - 1,
@@ -193,13 +194,14 @@ const List = defineComponent({
193194

194195
// Give cache to improve scroll experience
195196
endIndex = Math.min(endIndex + 1, state.mergedData.length);
196-
return {
197+
calRes.value = {
197198
scrollHeight: itemTop,
198199
start: startIndex,
199200
end: endIndex,
200201
offset: startOffset,
201202
};
202203
});
204+
203205
// =============================== In Range ===============================
204206
const maxScrollHeight = computed(() => calRes.value.scrollHeight! - props.height!);
205207

0 commit comments

Comments
 (0)