Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

103
Visualizações
How to select an option on Vue
<template>
 <select class="form-control mt-1" @change="selectUser">
  <option >select user</option>
  <option v-for="(user, index) in users" :key="index" {{user.first_name}}</option>
 </select>
</template>

<script>
selectUser(event){
 if(event.target.selectedIndex != 0){
   this.index = event.target.selectedIndex-1
   this.selectedUsers.push(this.users[this.index])
   this.users.splice(this.index, 1)
  }              
}
</script>

The idea of this script is that when you select an option it gets removed and added to another array of objects and it disappears from the select list. I want when this happened, the first option to get selected back again.

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

You can use v-model to get the selected item from <select>

<select v-model="selected">
        ......
</select>

and then use it this way:

<span>Selected: {{ selected }}</span>

about 4 years ago · Juan Pablo Isaza Relatório

0

The best way is to have :

  • a options and a selectedOption in the data.

  • A availableOptions as computed options, with options.filter(o => o !== this.selectedOption)

  • Bind the select with a v-model=selectedOption

  • bind the with the avaiableOptions

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda