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

184
Visualizações
Vuejs populate select options from api

Im begginer in VueJs so i have this problem

Here my code

<md-select placeholder="Seleccione Lote" v-model="selectedLote" name="lotes" id="lotes">
   <md-option  v-for="lote of lotes" value="lote.value">{{lote.text}}</md-option>
</md-select>

Then i have my array

data: () => ({
        lotes: [],
        selectedLote : null
    })

Then i populate this array using this (this.products is an array populated from an api request)

mounted(){
  this.fillLotesArray();
},
methods:{
fillLotesArray(){
            for(let product of this.products){
                if(this.lotes.findIndex(lote => lote.value === product._source.Lote) === -1){
                    this.lotes.push({value:product._source.Lote, text:product._source.Lote});
                }
            }
        }
}

Using console.logs i can see the array is filled correctly but the options dont

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

0

this is usually my standard way to write a select from an API

<template>
    <select v-model="selectedOption">
        <option v-for="(item, index) in options" :value="item.value" :key="index">{{ item.text }}</option>
    </select>
</template>

<script>
export default {
    name: 'ExampleOptions',
    data() {
        return {
            options: [],
            selectedOption: null,
        };
    },
    mounted() {
        this.loadOptions();
    },
    methods: {
        loadOptions() {
            api.getOptions().then((options) => {
                this.options = options;
            });
        },
    },
};
</script>

if you then need to have the data in correlation to others, such as a list of products or others, it is always advisable to use computed properties, to make sure that the data is always correct some examples

about 4 years ago · Juan Pablo Isaza Relatório

0

In Vue's repetition, a key is required.

v-bind is not set in value.


If you take {{lots}} and the value is expressed normally, try modifying the following.

<md-option  v-for="(lote, index) of lotes" :value="lote.value" :key="index">{{lote.text}}</md-option>
about 4 years ago · Juan Pablo Isaza Relatório

0

You just need to bind the select options value attribute

<md-select placeholder="Selection Lote" v-model="selectedLote" name="lotes" id="lotes">
   <md-option  v-for="(lote, index) of lotes" :value="lote.value" :key="index">{{lote.text}}</md-option>
</md-select>

For detailed usage of the key attribute, please see the key API documentation.

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