KoderSolutionKoderSolution LogoKoderSolution Logo
HomeArticlesTutorialsToolsRun CodeForumAI Lab
🖖

Vue

Topic Hub & Articles

Vue Intro

10 min

Recap Quiz

Gated

Milestone Assessment

Vue Get Started

10 min

Vue Directives

10 min

Vue Events

10 min

Recap Quiz

Gated

Milestone Assessment

Vue Forms

10 min

Vue Components

10 min

Vue Props

10 min

Recap Quiz

Gated

Milestone Assessment

Vue Methods

10 min

Vue Computed Properties

10 min

Vue Watchers

10 min

Recap Quiz

Gated

Milestone Assessment

Vue Class and Style Bindings

10 min

Vue Conditional Rendering

10 min

Vue List Rendering

10 min

Recap Quiz

Gated

Milestone Assessment

Vue Template Syntax

10 min

Vue Teleport

10 min

Vue Suspense

10 min

Recap Quiz

Gated

Milestone Assessment

Vue Transitions

10 min

Vue Mixins

10 min

Vue Custom Directives

10 min

Recap Quiz

Gated

Milestone Assessment

Vue Plugins

10 min

Vue Slots

10 min

Vue Provide / Inject

10 min

Recap Quiz

Gated

Milestone Assessment

Vue Dynamic Components

10 min

Vue Async Components

10 min

Composition API Intro

10 min

Recap Quiz

Gated

Milestone Assessment

ref vs reactive

10 min

Lifecycle Hooks

10 min

Dependency Injection

10 min

Recap Quiz

Gated

Milestone Assessment

Computed and Watch

10 min

Template Refs

10 min

Composable Functions

10 min

Script Setup

10 min

Progress
0%

0 / 32 Lessons

KoderSolutionKoderSolution LogoKoderSolution Logo

The world’s most advanced technical ecosystem for modern software engineers. Learn, build, and grow with next-generation developer tools and resources.

Facebook PageX (Twitter) ProfileYouTube ChannelContact Support

Engineering Newsletter

Subscribe for weekly software engineering tutorials, architecture guides, and developer tool updates.

Platforms

  • Technical Articles
  • Interactive Tutorials
  • AI Coding Lab
  • Developer Forum
  • Developer Tools

Pages

  • About Us
  • Contact Us
  • Privacy Policy
  • Terms of Service
  • Refund Policy
  • Disclaimer
  • Advertisement

Popular Topics

  • PHP
  • Laravel
  • Python
  • React.Js
  • MySQL
© 2026 KoderSolutionAll Rights Reserved
Developed Bymaksudur.dev
VueVue Tutorial
Lesson

Vue List Rendering

10 min reading
Free Course

Vue List Rendering: v-for Iteration and Unique Keys

Vue list rendering uses the v-for directive to display repeated elements from an array, object, or numeric range. Whenever the source array changes, Vue updates the rendered list automatically.

To update lists efficiently without losing input state or animations, Vue relies on a unique :key attribute on each looped item. The key acts as a stable ID so Vue can track each item across insertions, deletions, and sorting.

flowchart TD
    Data["Reactive Array (tasks)"] --> Loop["v-for='task in tasks' :key='task.id'"]
    Loop --> VDOM["Virtual DOM Nodes with Keys"]
    VDOM --> Patch["Targeted Reorder and Patch"]

Supported v-for Syntax Forms

  • Arrays: v-for="(item, index) in items" :key="item.id"
  • Objects: v-for="(value, key, index) in userSettings" :key="key"
  • Numeric Ranges: v-for="page in totalPages" :key="page" (starts at 1)
  • Multi-Element Groups: <template v-for="item in items" :key="item.id">

Practical SFC List Rendering Example

This task manager uses v-for with task.id as :key and mutates or replaces the reactive array inside <script setup>.

<script setup>
import { ref } from 'vue';

const tasks = ref([
  { id: 101, text: 'Review Vue 3 Documentation', completed: true },
  { id: 102, text: 'Build Auth Composable', completed: false },
  { id: 103, text: 'Write Component Tests', completed: false }
]);

function toggleTask(id) {
  const task = tasks.value.find((item) => item.id === id);
  if (task) task.completed = !task.completed;
}

function removeTask(id) {
  tasks.value = tasks.value.filter((item) => item.id !== id);
}
</script>

<template>
  <div class="todo-app">
    <h2>Task List</h2>
    <ul>
      <li
        v-for="task in tasks"
        :key="task.id"
        :class="{ done: task.completed }"
      >
        <span>{{ task.text }}</span>
        <button @click="toggleTask(task.id)">Toggle</button>
        <button @click="removeTask(task.id)">Remove</button>
      </li>
    </ul>
  </div>
</template>

<style scoped>
.done span {
  text-decoration: line-through;
  color: #64748b;
}
</style>

Common Mistakes

  • Using Array index as :key on Dynamic Lists: If you delete, insert, or reorder items, :key="index" shifts every remaining key and mixes up child component state. Always use a unique ID like task.id.
  • Passing an Object as :key: Keys must be primitive strings or numbers, not plain objects. Passing an object turns every key into "[object Object]".
  • Filtering Inside v-for with v-if: Putting v-if="task.completed" on the same tag as v-for fails in Vue 3 because v-if runs first. Compute a filtered array instead.

Frequently Asked Questions

Which array methods trigger reactive updates in Vue 3?

Mutation methods like push(), pop(), shift(), unshift(), splice(), sort(), and reverse() trigger updates automatically. Replacing tasks.value with .filter() or .map() also works cleanly.

Where do I put :key when using <template v-for>?

Place :key directly on the <template v-for> tag itself rather than duplicating it on child elements inside the template block.

Can v-for iterate over a component instead of an HTML tag?

Yes. Write <TaskCard v-for="task in tasks" :key="task.id" :task="task" /> and pass the item explicitly through props.

Save Your Progress

Unlock Your
Full Potential.

Sign in to track your learning journey, earn industry-recognized certificates, and join our elite developer community.

Quick Access With

Enterprise-Grade Security Protocol
Lesson Recap Quiz Available

Test Your Knowledge

You've completed this section! Take a quick 5-question quiz to check your understanding.

Related Developer Tools & Topic Hub

Vue Topic Hub
JSON Formatter
Validate and format JSON payloads
HTML Formatter
Format HTML templates
CSS Formatter
Clean and format stylesheets
All Vue Articles
Deep-dive guides, tips & discussions
PreviousVue Conditional Rendering
Continue JourneyTake Recap Quiz

Stuck on this lesson?

Join our community of senior developers.

Ask in Forum