但我想要更有效的循环方式。有谁知道如何使循环从 5 开始? 最佳-6ren">
gpt4 book ai didi

vue.js - 如何从特定索引渲染 v-for

转载 作者:搜寻专家 更新时间:2023-10-30 22:11:22 25 4
gpt4 key购买 nike

我想从 assumption 从数字 5 到 10 循环 v-for 。循环希望在 5 点开始并在 10 点结束。

我试过了

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

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

最佳答案

对于你的例子来说是可能的:

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

和挂载范围函数:

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

并在 jsfidle 中采样.

如果想了解更多github issue可以帮助你。

关于vue.js - 如何从特定索引渲染 v-for,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49715339/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com