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

289
Visualizações
How to pass value to v-model with emit?

I'm trying to pass value from a select field to v-model but the code only works in a v-text-field.

<script>
    export default {
        name: 'FormSelect',
        props: {
            modelValue: {
                type: [String, Number],
                default: '',
            },
            label: {
                type: String,
                default: '',
            },
            items: {
                type: Array,
            },
        },
        model: {
            prop: 'modelValue',
            event: 'change',
        },
    };
</script>
<template>
    <div>
        <v-select
            :label="label"
            v-bind:value="modelValue"
            @input.native="$emit('change', $event.target.value)"
            :items="items"
        ></v-select>
    </div>
</template>

<template>
    <div class="form">
        <v-flex xs10 sm8 md6 lg5>
            <v-card>
                <FormTitle />
                <ModalFormMessage />
                <v-form ref="form" class="d-flex flex-column">
                    <FormSelect
                        v-model="vulnerabilities.vulnerability"
                        label="Vulnerability"
                        :items="items.vulnerability"
                    />
                    <FormInputs
                        v-model="vulnerabilities.evidence"
                        label="Eevidence"
                        type="file"
                    />
                    <FormInputs
                        v-model="vulnerabilities.solution"
                        label="Solution"
                        type="text"
                    />
                    <FormBtns />
                </v-form>
            </v-card>
        </v-flex>
    </div>
</template>

In the select field is not returning the selected value, how can I make the value I select be passed to the v-model in the child component too?

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

0

You should emit an event with name input :


@input="$emit('input', $event.target.value)"
about 4 years ago · Juan Pablo Isaza Relatório

0

I solved it as follows

methods: {
  changeSelect: function () {
    this.$emit('input', this.modelValue);
  },
},
<template>
    <div>
        <v-select
            :label="label"
            @input="changeSelect()"
            v-model="modelValue"
            :items="items"
        ></v-select>
        <p>{{ modelValue }}</p>
    </div>
</template>

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