Performance: v-for for list rendering
MEDIUM IMPACT
This affects how quickly the browser can render lists and update the DOM when data changes.
<template>
<ul>
<li v-for="item in items" :key="item.id">{{ item.name }}</li>
</ul>
</template>
<script setup>
const items = Array.from({ length: 1000 }, (_, i) => ({ id: i, name: `Item ${i}` }));
</script><template>
<ul>
<li v-for="item in items">{{ item.name }}</li>
</ul>
</template>
<script setup>
const items = Array(1000).fill({ name: 'Item' });
</script>| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| v-for without key | Creates all nodes every update | Triggers reflow for every item | High paint cost due to full re-render | [X] Bad |
| v-for with unique key | Updates only changed nodes | Minimal reflows on update | Lower paint cost | [OK] Good |
| v-for with virtual scrolling | Creates only visible nodes | Very few reflows | Minimal paint cost | [OK] Good |