简体   繁体   中英

Vue.js - while loop alternative

I want to print a component as many times as an int. Something like:

x = 5;
while(x >= 5)
{
<component></component>
x++;
}

I know about v-for loop but I would like to print with a number not with an array. Is it possible?

v-for can be also used in a range:

 new Vue({ el:"#app" });
 .as-console-wrapper { max-height: 40%!important; }
 <script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script> <div id="app"> <ul> <li v-for="index in 5" :key="index">{{index}}</li> </ul> </div>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM