简体   繁体   English

Vue.js - while 循环替代

[英]Vue.js - while loop alternative

I want to print a component as many times as an int.我想打印一个与 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.我知道 v-for 循环,但我想用数字而不是数组打印。 Is it possible?是否可以?

v-for can be also used in a range: v-for也可以在一个范围内使用:

 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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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