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

307
Visualizações
Select input cannot have a default value (Vue.js)

Trying to set a default value to a simple select input with "selected" doesn't work.

I am making a blog in Vue.js and the blog posts can be assigned to different categories. However, when editing a post, I want the select input to have a default value if the post is already inside a category. The pseudo-code would look like so: "if category.id equals post.category.id".

This is my input:

<label>
  <VeeValidateField name="post_category" as="select">
    <option value="" disabled>Set to folder</option>
    <option value="0">none</option>
    <option v-for="category in categories"
      :key="category.id"
      :value="category.id"
      :selected="category.id === post.category.value"
    >
      {{ category.category_name }}
    </option>
  </VeeValidateField>
</label>

Although there can be a default value with a multiple select input, that is not my use case.

Is this a bug or am I doing something wrong?!

Thank you!

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

0

I solved this by using v-model and setting the value in data to the following expression:

data() {
    return {
      categoryValue: this.$props.login ? this.$props.login.login_category.value : ""
    }
  }

and this is the markup:

<label>
    <VeeValidateField v-model="categoryValue" name="login_category" as="select">
        <option value="" disabled>Set to folder</option>
        <option value="0">none</option>
        <option v-for="category in categories"
                :key="category.id"
                :value="category.id">
          {{ category.category_name }}
        </option>
    </VeeValidateField>
</label>

So when the property categoryValue evaluates, the select input either gets a default value or none at all.

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