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

139
Visualizações
Why isn't a reactive variable watchable?

I am developing a simple application in Vue3 and TypeScript. I defined an interface and initialized a reactive variable scrap that I the wanted to watch:

interface Scrap {
  Text: string,
  ModificationDate: string,
}
const scrap = ref<Scrap>({ Text: '', ModificationDate: '' } as Scrap)
watch(() => scrap, () => console.log('change'))

scrap.Text is modified in the application UI and I see these changes in DevTools → Vue.

The watch() callback is however not fired, despite that change. What is the reason for that?

I tried both watch(scrap, () => console.log('change')) and watch(() => scrap, () => console.log('change')) but there were no difference in behaviour (nor errors or warnings).

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

0

In case the whole object is watched, it should be a deep watcher:

watch(scrap, () => console.log('change'), { deep: true })

Otherwise a specific property should be watched:

watch(() => scrap.value.Text, () => console.log('change'))
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