CHAPTER 10
Beginner
Conditional Rendering and Lists
Updated: May 18, 2026
5 min read
# CHAPTER 10
Conditional Rendering and Lists
1. Chapter Introduction
Showing or hiding UI elements based on state, and rendering dynamic lists of data, are the two most common tasks in any frontend application. Vue'sv-if/v-show and v-for directives handle both elegantly.
2. Learning Objectives
-
Use
v-if,v-else-if,v-elsefor conditional rendering.
-
Use
v-showfor toggling visibility.
-
Render dynamic lists with
v-for.
-
Optimize lists with proper
:keyusage.
- Build a filtered product listing.
3. Conditional Rendering Deep Dive
vue
4. List Rendering Deep Dive
vue
5. Common Mistakes
-
Using index as
:keyfor mutable lists:v-for="(item, i) in items" :key="i"causes incorrect DOM recycling when items are reordered or removed. Useitem.id.
-
v-ifandv-foron the same element: Never. Use a<template>wrapper.
6. MCQs
Question 1
v-for :key best practice?
Question 2
What renders when no v-for items match a filter?
Question 3
v-show vs v-if for performance with frequent toggles?
Question 4
v-for with a computed filtered list is better because?
Question 5
computed caches based on?
Question 6
v-for iterating an object gives?
Question 7
v-for="n in 5" iterates?
Question 8
Computed filtered + sorted list vs method?
Question 9
<template v-for> renders?
Question 10
v-else requires?
7. Interview Questions
-
Q: Why is using index as
:keyinv-fora bad practice?
- Q: How would you implement a filterable, sortable product list in Vue?
8. Summary
Conditional rendering withv-if/v-show and list rendering with v-for + :key are the two most-used Vue features. Computed properties power efficient filter and sort operations. The product listing project demonstrates how these combine with reactivity to create fully interactive, zero-JavaScript-DOM-manipulation UIs.