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

301
Views
How to v-bind the button id attribute using Vuejs?

I'm sure there is a way to do that, but I can't understand why it doesn't work for me (I'm completely new to vuejs)

I tried using the button tag:

<div v-for="line in lines">
    <button v-bind:id="line.id" name="availabilityCheck" type="button">
        Check availability
    </button>
</div>

And the button type input:

<div v-for="line in lines">
    <input v-bind:id="line.id" name="availabilityCheck" type="button" value="Check availability" />
</div>

What happens is that the browser removes the part v-bind:id="line.id" so basically the generated buttons do not have an id.

about 4 years ago · Santiago Trujillo
2 answers
Answer question

0

I am not sure why it is not working for you but it should ideally work if your lines array contains id property in the objects.

Demo :

new Vue({
  el: '#app',
  data: {
    lines: [{
        id: 1
    }, {
        id: 2
    }, {
        id: 3
    }, {
        id: 4
    }, {
        id: 5
    }]
  }
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>
<div id="app">
  <div v-for="line in lines" :key="line.id">
    <input v-bind:id="line.id" name="availabilityCheck" type="button" value="Check availability" />
  </div>
</div>

Screenshot :

enter image description here

about 4 years ago · Santiago Trujillo Report

0

<div v-for="line in lines">
    <button :id="'lin'+line.id" name="availabilityCheck" 
        type="button">
        Check availability
    </button>
</div>

Add a constant on prefix may be it work

about 4 years ago · Santiago Trujillo 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!