Recall & Review
beginner
What does the
v-for directive do in Vue?The
v-for directive repeats a block of HTML for each item in a list or array, rendering multiple elements dynamically.Click to reveal answer
beginner
How do you write a
v-for loop to render items in an array called fruits?Use
<li v-for="(fruit, index) in fruits" :key="index">{{ fruit }}</li> to loop through fruits and display each fruit with a unique key.Click to reveal answer
intermediate
Why is the
:key attribute important when using v-for?The
:key helps Vue track each item uniquely, improving rendering performance and avoiding bugs when the list changes.Click to reveal answer
intermediate
Can
v-for be used to loop over objects? How?Yes. You can loop over an object’s properties using
v-for="(value, key) in object", where key is the property name and value is its value.Click to reveal answer
beginner
What happens if you forget to add a
:key in a v-for loop?Vue will warn you in the console. Without keys, Vue may reuse elements incorrectly, causing unexpected UI bugs.
Click to reveal answer
What is the correct syntax to loop over an array
items using v-for?✗ Incorrect
Option A uses the correct syntax with
v-for="item in items" and a unique :key.Why should you always provide a
:key when using v-for?✗ Incorrect
The
:key helps Vue identify each element uniquely for efficient updates.Which of these is a valid way to loop over an object with
v-for?✗ Incorrect
Option B correctly destructures the object into key and value pairs.
What will happen if you use the same
:key for multiple items in a v-for list?✗ Incorrect
Duplicate keys confuse Vue’s rendering system and can cause UI errors.
Which directive is used to repeat elements in Vue?
✗ Incorrect
v-for is the directive for looping over lists.Explain how to use
v-for to render a list of items in Vue. Include why the :key attribute is important.Think about how you would show a list of fruits on a webpage using Vue.
You got /4 concepts.
Describe how you can loop over an object’s properties using
v-for in Vue.Imagine you have an object with names and ages and want to show both.
You got /3 concepts.