Performance: v-for with objects
MEDIUM IMPACT
This affects rendering speed and DOM update performance when looping over object properties in Vue templates.
<template>
<ul>
<li v-for="(value, key) in items" :key="key">
{{ key }}: {{ value }}
</li>
</ul>
</template><template>
<ul>
<li v-for="(value, key) in items" :key="Math.random()">
{{ key }}: {{ value }}
</li>
</ul>
</template>| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| v-for with random keys | Full node replacement on each update | Triggers full reflow per update | High paint cost due to many node changes | [X] Bad |
| v-for with stable keys (object keys) | Only changed nodes updated | Minimal reflows limited to changed items | Lower paint cost with fewer DOM changes | [OK] Good |