I'm working on printing out the page numbers a user may click on for a pager component in Vue.js. I see that the docs clearly say v-for can be used for a range:
v-for can also take an integer. In this case it will repeat the template that many times.
<div> <span v-for="n in 10">{{ n }} </span> </div>
Result:
1 2 3 4 5 6 7 8 9 10
Per https://v2.vuejs.org/v2/guide/list.html#v-for-with-a-Range
I have not found anyway to specify the starting value for n. It seems that it starts at 1 and increments by 1 until 10.
Is there anyway to start n at, say, 5?
It almost seems like I'll need to create a method or computed property that will return an array of the exact values I want iterated in place of the static 10.
Anyone have any other thoughts?
There is no way to start a
v-for
at n.However, starting at an offset is as simple as adding the offset to your value and then stopping when you hit max.
If you need more control, a
computed
property is most definitely the way to go, as it will provide you full control over whatever you're iterating over.