Do v-for only with number

Asked

Viewed 580 times

1

It is possible to make a v-for using only a total number?

Example:

I would pass a variable with value 10, it would loop from 1 to 10, like the JS example below:

for(var i = 1; i <= num_parcelas; i++){
      mostrar += "<option value='" + i + "'>" + i + "</option>";
    }

1 answer

3


You can use the v-for with a range. For example:

<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<div id="range" class="demo">
  <select>
    <option v-for="n in 10" :value="n">{{ n }}</option>
  </select>
</div>
<script>
  new Vue({ el: '#range' })
</script>

See on documentation.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.