【发布时间】:2021-05-03 07:35:50
【问题描述】:
我用过svelte-infinite-loading,一开始效果很好,
但随着列表变得很长,我的 Web 应用开始使用大量内存,最多使用 2gb。
所以,我需要虚拟化这个无限列表。
我按照svelte-infinite-loading作者的推荐使用了svelte-tiny-virtual-list:
<script>
....
function onInfinite({ detail }) {
const skip = items !== undefined ? items.length : 0;
fetchItems(skip).then((data) => {
if (data.length === 0) {
items = [];
detail.complete();
return;
}
if (items === undefined) items = data;
else items = [...items, ...data];
detail.loaded();
});
}
onMount(() => {
fetchItems(0).then((data) => {
Items = data;
});
});
</script>
{#if items !== undefined}
{#if items.length === 0}
<p><i>No items found</i></p>
{:else}
<VirtualList
itemCount={items.length}
itemSize={200}
height="100%">
<div slot="item" let:index>
<Item
item={items[index]} />
</div>
<div slot="footer">
<InfiniteLoading on:infinite={onInfinite} />
</div>
</VirtualList>
{/if}
{/if}
页面加载时问题来了:
前几个项目被正确获取并显示,但页面增长到异常长度,然后列表消失,我收到以下错误:
InfiniteLoading.svelte:103 executed the callback function more than 10 times for a short time, it looks like searched a wrong scroll wrapper that doest not has fixed height or maximum height, please check it.
我做错了什么?
【问题讨论】: