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

302
Vistas
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 Respuestas
Responde la pregunta

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 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