Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Vue 3 Loop Statements

Vue.js Loop Statements

In Vue, loop statements are mainly implemented through the v-for directive, used to iterate over arrays or objects and generate corresponding numbers of elements.

Use the v-for directive on an element to loop-render elements based on the source data's array or object.

Iterate over an array:

v-for="(item, index) in items"

Iterate over an object:

v-for="(value, key, index) in object"

v-for can bind data to an array to render a list:

v-for Example

 

       

  1.       {{ site.text }}

       

  2.  

Try it »

v-for also supports an optional second argument, whose value is the index of the current item:

v-for Example

index is the index value of the list item:

 

       

  1.       {{ index }} -{{ site.text }}

       

  2.  

Try it »

Template