v-for
Last updated
What is v-for?
The v-for directive is used to render an HTML element, a block of elements, or even a component based on an array, an object, or a set number of times.
When using this directive it is important to assign a unique key to each item to avoid issues and improve performance. This directive follows the item in items syntax.
Example
<script setup>
import { ref } from 'vue';
const foods = ref([
{id: 1, name: "apple"},
{id: 2, name: "pear"},
{id: 3, name: "pizza"}
]);
</script>
<template>
<p v-for="food in foods" :key="food.id">{{ food.name }}</p>
</template>
Free resources to learn v-for
- Official docsv-for Documentation
More in stage 10: SSG
v-for: common questions
Can I learn v-for in Hindi?
This lesson is written in English. Once you sign in, open it in the interactive course and ask the AI tutor to explain v-for in Hindi or Hinglish. The tutor answers from this lesson’s own text, so it stays on the syllabus, and it runs on your own Google, OpenAI or Anthropic key.
Is this v-for tutorial for beginners?
It is lesson 53 of 84 in the free Vue roadmap, in stage 10, SSG. If you are new to Vue, start from stage 1 and come back here in order; if you already know the earlier stages, this lesson stands on its own.