0
0
Vueframework~10 mins

v-for for list rendering in Vue - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - v-for for list rendering
Start with array data
Vue template reads v-for directive
Loop over each item in array
Create DOM element for each item
Insert elements into parent container
Render list on page
Vue reads the v-for directive, loops over the array, creates elements for each item, and renders them inside the parent container.
Execution Sample
Vue
<template>
  <ul>
    <li v-for="item in items" :key="item.id">{{ item.name }}</li>
  </ul>
</template>

<script setup>
const items = [{ id: 1, name: 'Apple' }, { id: 2, name: 'Banana' }]
</script>
This code loops over the items array and renders each item's name inside a list item.
Execution Table
StepActionCurrent ItemDOM Element CreatedParent Container
1Start loopN/AN/A<ul> (empty)</ul>
2Process first item{ id: 1, name: 'Apple' }<li>Apple</li><ul><li>Apple</li></ul>
3Process second item{ id: 2, name: 'Banana' }<li>Banana</li><ul><li>Apple</li><li>Banana</li></ul>
4Loop endsN/AN/A<ul><li>Apple</li><li>Banana</li></ul>
💡 All items processed, loop ends and list is fully rendered.
Variable Tracker
VariableStartAfter 1After 2Final
items[{id:1,name:'Apple'},{id:2,name:'Banana'}]SameSameSame
itemN/A{id:1,name:'Apple'}{id:2,name:'Banana'}N/A
Key Moments - 2 Insights
Why do we need to use :key with v-for?
The :key helps Vue track each item uniquely during updates, so it can efficiently update only changed elements. See execution_table rows 2 and 3 where each item creates a separate <li>.
What happens if the array is empty?
If the array is empty, the loop does not run and no list items are created. The parent container remains empty, as shown in execution_table step 1 before looping starts.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what is the DOM content inside <ul> after step 3?
A<li>Apple</li>
B<li>Apple</li><li>Banana</li>
CEmpty <ul>
D<li>Banana</li>
💡 Hint
Check the 'Parent Container' column at step 3 in the execution_table.
At which step does the loop finish processing all items?
AStep 2
BStep 3
CStep 4
DStep 1
💡 Hint
Look at the 'Action' column for the step where the loop ends in the execution_table.
If the items array had 3 objects, how many <li> elements would be created?
A3
B2
C1
D0
💡 Hint
Refer to the pattern in execution_table rows 2 and 3 where each item creates one
  • .
  • Concept Snapshot
    v-for directive loops over arrays or objects.
    Syntax: v-for="item in items".
    Use :key for unique identification.
    Creates one DOM element per item.
    Renders list inside parent container.
    Efficient updates with keys.
    Full Transcript
    The v-for directive in Vue loops over an array or object to render a list of elements. Vue reads the v-for, then for each item in the array, it creates a DOM element, like a list item, and inserts it into the parent container. Using a unique :key helps Vue track each element for efficient updates. If the array is empty, no elements are created. This process repeats until all items are rendered, producing a visible list on the page.