Rendering Lists
Part of the Fundamentals section of Coddy's Vue journey. Lesson 23 of 55.
Use v-for to render each array item. This template creates two list items, showing Red and Blue.
const colors = ref(['Red', 'Blue']);
// <ul><li v-for="color in colors" :key="color">{{ color }}</li></ul>The alias color refers to one item inside the repeated element. For objects, read properties such as color.name and use a stable unique id as the key. Rendering follows the source array order when that array changes.
Challenge
EasyRender the supplied team array as one li per name inside ul#result. Use v-for and a unique name key. Button #reverse must reverse the array so the displayed order follows it.
Try it yourself
<!doctype html><html><head><meta charset="UTF-8"><title>Vue practice</title></head><body><div id="app"></div><script type="module" src="./main.js"></script></body></html>This lesson includes a short quiz. Start the lesson to answer it and track your progress.
All lessons in Fundamentals
2Reactive State
Reactive RefsUpdating Refs in ScriptEvent Handler ArgumentsReactive ObjectsRecap: Reactive State5Conditions and Lists
Conditional BranchesShow without UnmountingRendering ListsStable List IdentityRecap: Conditions8Component Communication
Emitting EventsEvent PayloadsLifting Shared StateDefault and Named SlotsRecap: Shared Panel11Project: Community Board
Board StructureAdding Community Tasks