Subscribe on changes!

mouseover mouseleave multiple render of list

avatar
Oct 5th 2023

I believe this is working as expected.

The isHovered property of each item is accessed during component rendering. This will add those properties as dependencies of the rendering process. When any dependency of rendering changes, it will trigger a re-render.

The re-render will create a new tree of VNodes. Those VNodes will then be paired up with VNodes from the previous rendering and any changes will be patched to the corresponding DOM nodes. No new DOM nodes will need to be created, the existing DOM nodes will just be updated. In this specific example, that will involve updating the text nodes that show true or false.

Usually this type of rendering update will be very fast, as modifying the DOM is the most expensive part of the process. However, if you find yourself in a situation where performance is critical and needs to be improved then you could either split this component up into multiple components (as each one renders separately from the others), or you could use v-memo to manually manage which reactive dependencies trigger rendering updates for specific nodes.

The following sections of the docs explain how Vue's rendering works and how to tweak it for optimal performance:

If you want to discuss how Vue's rendering/reactivity works in more detail then I recommend the Vue Discord server.

avatar
Oct 5th 2023

Yes, you are right, v-memo fix this problem. I updated the example and its better.