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

157
Vistas
Setting a default value in the composition API (Vue 3)

I've created some messages for my form. One of them is a message where the content will never change (As opposed to my error message where the content will change depending on the error).

<p class="form__success-message" v-else-if="soFarSoGood">
  {{ soFarSoGoodMsg }}
</p>

statuses() {
  return {
    error: false,
    soFarSoGood: false,
    submissionReady: false,
    submitted: false,
    };
  },
messages() {
  return {
    errorMsg: "",
    soFarSoGoodMsg: "All good so far! 👌",
    submittedMsg: "",
    };
  },

The problem I'm experiencing is this will return null in the DOM.

However, the intended message will appear in the DOM if I set the value to an empty string initially and I update the message once the state of the form changes.

messages() {
    return {
      errorMsg: "",
      soFarSoGoodMsg: "",
      submittedMsg: "",
    };
  },
  methods: {
    approveFormStatus(input) {
      if (input !== null) {
       this.soFarSoGoodMsg = "All good so far! 👌"; 
      }
    }
  }

I want this message to be the default message for that specific condition. I don't want to have to set it in one of my methods.

What's the solution to this and what am I misunderstanding?

Cheers

about 4 years ago · Juan Pablo Isaza
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