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

156
Visualizações
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 à 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