web: 减少重绘

This commit is contained in:
Xwite
2023-05-11 14:43:07 +08:00
parent 8dd81481bd
commit 2b1a7bf8d3
+7 -7
View File
@@ -1,8 +1,5 @@
<template> <template>
<div <div :class="{ 'cata-wrapper': true, correctSize }" :style="popupTheme">
:class="{ 'cata-wrapper': true, visible: popCataVisible }"
:style="popupTheme"
>
<div class="title">目录</div> <div class="title">目录</div>
<virtual-list <virtual-list
style="height: 300px; overflow: auto" style="height: 300px; overflow: auto"
@@ -77,9 +74,12 @@ const virtualListIndex = computed(() => {
return Math.floor(index.value / 2); return Math.floor(index.value / 2);
}); });
onUpdated(() => { const correctSize = ref(false);
// dom更新触发ResizeObserver,更新虚拟列表内部的sizes Map watch(popCataVisible, (visible) => {
virtualListRef.value.scrollToIndex(virtualListIndex.value); // 组件挂载时不可见 virtualList计算首屏的size为0 重新触发其内部的ResizeObserver
if (visible && !correctSize.value) correctSize.value = true
if (!visible) return;
nextTick(() => virtualListRef.value.scrollToIndex(virtualListIndex.value));
}); });
</script> </script>