如何在循环时获取特定数字,在我的情况下,我只想获得5个及以上数字或在我想要的范围内.
<select name="" id="input" class="form-control" v-model="selectcompetitionyear">
<option v-for="n in 8" :value="n">Previous {{n}} games</option>
</select>
结果将是
<select name="" id="input" class="form-control" v-model="selectcompetitionyear">
<option value="5">Previous 5 games</option>
<option value="6">Previous 6 games</option>
<option value="7">Previous 7 games</option>
<option value="8">Previous 8 games</option>
</select>
解决方法:
这取决于用例,但其中一种方法是:
var vm = new Vue({
el: '#app',
data: {
selectcompetitionyear:5
},
methods:{
getNumbers:function(start,stop){
return new Array(stop-start).fill(start).map((n,i)=>n+i);
}
}
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.3.3/vue.min.js"></script>
<div id="app" class="l-container l-vPad--mid">
<select name="" id="input" class="form-control" v-model="selectcompetitionyear">
<option v-for="n in getNumbers(5,9)" :value="n">Previous {{n}} games</option>
</select>
</div>