Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

84
Views
For loop in vuejs like php

It is possible in vuejs to v-for a loop like php?

I want this output:

<select>
    <option>2</option>
    <option>1</option>
    <option>0</option>
</select>

My code (ticket.quantity = 2):

<select>
    <option v-for="index in ticket.quantity" :value="index" :key="index">{{index}}</option>
</select>

My output:

<select>
    <option>2</option>
</select>
about 4 years ago · Santiago Gelvez
2 answers
Answer question

0

You can try to loop ticket.quantity + 1 :

new Vue({
  el: '#demo',
  data() {
    return {
      ticket: {quantity: 2}
    }
  }
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>
<div id="demo">
  <select>
    <option v-for="(q, index) in ticket.quantity + 1" :value="index" :key="index">{{index}}</option>
  </select>
</div>

about 4 years ago · Santiago Gelvez Report

0

The answer of Nikola didn't worked for me completely but I managed to solve it like this:

<select>
    <option value="0" selected>0</option>
    <option v-for="index in parseInt(ticket.quantity)" :value="index" :key="index">{{index}}</option>
</select>
about 4 years ago · Santiago Gelvez Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!