如何从特定索引呈现 v-for [英] How to render v-for from particular index

查看:37
本文介绍了如何从特定索引呈现 v-for的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在 v-for 中循环,假设从数字 5 到 10 .循环希望从 5 开始,在 10 结束.

我已经试过了

<div v-for="n in 10" v-if="n>=5"></div>

但我想要更有效的循环方式.有谁知道如何让循环从 5 开始?

解决方案

它可能为您的示例:

...这里有一些代码

和挂载范围函数:

var app = new Vue({el: '#app',方法:{范围:函数(开始,结束){return Array(end - start + 1).fill().map((_, idx) => start + idx)}}});

jsfidle 中的示例.

如果想了解更多,github issue可以帮助您.

I want to loop in v-for from suppose from number 5 to 10 . The loop want to be started at 5 and end at 10.

I have tried this

<div v-for="n in 10" v-if="n>=5"></div>

But I want more effective way of doing the loop . Does anyone knows how to do so that loop starts at 5 ?

解决方案

Its possible for your example:

<div v-for="i in range(5, 10)">
... some code here
</div>

and mount range function:

var app = new Vue({
  el: '#app',
  methods:{
    range : function (start, end) {
      return Array(end - start + 1).fill().map((_, idx) => start + idx)
   }
  }
});

and sample in jsfidle.

If want know more than this github issue can help you.

这篇关于如何从特定索引呈现 v-for的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆