0
0
Fork 0

perf: remove setTimeOut insteaduse requestAnimationFrame

This commit is contained in:
Javier Segarra 2024-12-04 09:15:02 +01:00
parent dcbb0da8c0
commit 98b8124577
1 changed files with 7 additions and 8 deletions

View File

@ -78,17 +78,16 @@ watch(
{ immediate: true } { immediate: true }
); );
const onItemSaved = (updatedItem) => { const onItemSaved = (updatedItem) => {
scrollToItem(updatedItem.items[0].itemFk); requestAnimationFrame(() => {
scrollToItem(updatedItem.items[0].itemFk);
});
}; };
const scrollToItem = async (id) => { const scrollToItem = async (id) => {
await nextTick(); const element = itemRefs.value[id]?.$el;
setTimeout(() => { if (element) {
const element = itemRefs.value[id]?.$el; element.scrollIntoView({ behavior: 'smooth', block: 'center' });
if (element) { }
element.scrollIntoView({ behavior: 'smooth', block: 'center' });
}
}, 100);
}; };
provide('onItemSaved', onItemSaved); provide('onItemSaved', onItemSaved);
</script> </script>