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

217
Visualizações
Reactive default prop value

In the below:

  props: {
    id: {
      type: String,
      default() {
        return this.$route.params.id;
      },
    },
  },

then, supposing the parent component does not provide a value, I would expect the value of the id prop to change whenever the route changes to a new id. However this does not seem to be the case. Is my understanding correct? And is there a way to achieve reactivity here? Otherwise I'm thinking of setting required: false on it and then I'll have to have some computedId computed field, but I'd rather do it straight in the props section

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

0

Wouldn't it be better to just use computed? Or use watch to listen to the id and perform the force refresh function, but I don't really know how to set the action directly in the props

about 4 years ago · Juan Pablo Isaza Relatório

0

It's not a good idea to provide a default value base on a variable directly in props, the default in props is considered to provide a static value instead of a reactive value


use a computed value instead of props in your template may be a better practice

<div>{{ computedId }}</div>


  props: {
    id: {
      type: String,
    },
  },
  computed: {
     computedId() {
        return this.value || this.$route.params.id
     }
  }
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