Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

131
Vistas
In Vue, use select to choose an object in an array of objects

I have a select element with options, which loops through an array of objects (services).

<select placeholder="Vælg ydelse">
    <option v-for="service in services" :key="service.id">
        {{service.name}}
    </option>
</select>

In my data object, I have

chosenService: {
    id: 42,
    name: "some service",
    group: {
        id: 2,
        name: "some group within the service",
    },
    additions: [],
    classSignupMoreActive: false,
},

Which I'd like to be retrieved once the select is changed.

Finally, I'm sending the services array from the parent, as all of this is happening in a component. I'm not sure if this is the most correct way to do it.

Like this:

<Modal
  :show="showModal"
  @close="showModal = false"
  title="Modal Title"
  :services="this.services"
>
</Modal>
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You can use v-model and pass object to :value property of option:

new Vue({
  el: "#demo",
  data() {
    return {
      services: [{id: 42, name: "some service", group: {id: 2, name: "some group within the service",}, additions: [], classSignupMoreActive: false,}, {id: 43, name: "some other service", group: {id: 2, name: "some group within the service",}, additions: [], classSignupMoreActive: false,}],
      chosenService: {},
    }
  }
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>
<div id="demo">
  <select v-model="chosenService" placeholder="Vælg ydelse">
    <option v-for="service in services" :key="service.id" :value="service">
        {{service.name}}
    </option>
  </select>
  chosenService = {{ chosenService }}
</div>

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda