Skip to content
Learn Netverks

Lesson

Step 17/36 47% through track

lists-vfor

Lists with v-for

Last reviewed May 28, 2026 Content v20260528
Track mode
client_vue
Means
In-browser Vue TS
Reading
~1 min
Level
intermediate

This lesson

This lesson teaches Lists with v-for: the concepts, APIs, and habits you need before advancing in Vue.

Lists without stable keys break focus, animation, and state in production tables and feeds.

You will apply Lists with v-for in contexts like: Greenfield SPAs, dashboards, design systems, and full-stack apps that pair Vue with PHP or Node APIs.

Write TypeScript, click Run—Vue 3 loads from CDN with the template compiler, mountApp shows UI in #app, and printOutput feeds the terminal.

When you can explain the previous lesson's ideas without copying starter code.

Render lists with v-for. Always provide a stable key so Vue can match rows across updates when order changes.

Syntax

<li v-for="task in tasks" :key="task.id">
  {{ task.label }}
</li>

You can also write (item, index) in items when you need the index—avoid using index as key for dynamic lists.

Keys

  • Use stable IDs from data (user.id), not array index—unless the list is static and never reordered.
  • Keys are hints for reconciliation—they do not appear in the DOM.
  • Do not generate random keys on every render.

Important interview questions and answers

  1. Q: Why not index as key?
    A: Reordering, inserting, or deleting items can attach wrong state to the wrong row.
  2. Q: v-for with v-if on same element?
    A: Avoid—filter in computed or nest elements; v-for should have priority clarity.

Self-check

  1. Where does the :key go?
  2. When is index-as-key acceptable?

Challenge

Task list

  1. Add a fourth task to the array.
  2. Toggle done on one task and confirm line-through styling.

Done when: four tasks render with stable keys and done styling.

Pitfall: Using array index as :key when items reorder causes wrong DOM reuse—prefer stable ids.

Interview tip Lesson completion confidence

Can you explain this lesson in 30 seconds without reading notes?

Not saved yet.

Playground

Runs in your browser in a sandboxed frame. Backend runners appear when this track’s profile allows them.

Check yourself

Multiple choice — immediate feedback.

Discussion

Past discussion is visible to everyone. Only logged-in users can post comments and replies.

Starter discussion topics

  • Key choice?
  • Index key risk?

Sign up or log in to post comments and sync lesson progress across devices.

No discussion yet. Be the first to ask a question.

Jump