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

196
Views
how to pass the key as select option value from v-for when changed (VueJS)

I'm working with Vue 3 and Bootstrap 5.

I have a select with multiple options. Now I'm displaying my option.TEXT and this value will also be passed into my methods when I change something. But I want to pass the key (option.ID) when I change something.

But I also want my v-model to be my option.ID but displaying my option.TEXT.

How can I achieve this without checking it in the methods itself.

SELECT:

<select class="form-select" v-model="value" @change="get_key()">
    <option v-for="option in options" :key="option.ID">
        {{ option.TEXT }}
    </option>
</select>

OPTIONS ARRAY:

[
  {  "ID": 1,
     "TEXT": "One"
  },
  {  "ID": 2,
     "TEXT": "Two"
  },
  {  "ID": 3,
     "TEXT": "Three"
  },
]
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

The option attribute value should be bound to the option.ID :

<select class="form-select" v-model="value" @change="get_key()">
    <option v-for="option in options" :key="option.ID" :value="option.ID">
        {{ option.TEXT }}
    </option>
</select>
about 4 years ago · Juan Pablo Isaza 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!