v-for reverse order by iterating in descending way

Viewed 209

I want to make a loop that will go from 5 to 0. I don't know if I'm missing something obvious but there doesn't seem to be a way of doing it without creating an array and reversing.

Here's how I'm doing it now:

new Vue({
   el: '#app'
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>
<div id="app">
  <span v-for="value in Array.apply(null, {length: 5}).map(Number.call, Number).reverse()">{{ value }} | </span>
</div>

Is there an easier way without that one-liner hack?

1 Answers

I think this another code hack which could help you :

new Vue({
   el: '#app'
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>
<div id="app">
  <span v-for="value in 5">{{ 5-value }} | </span>
</div>

Related