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

147
Visualizações
Transferring data from one child component to the parent component to a different child component in Vue without vuex

so i'm new to Vue and i'm trying to pass text from a child component(InputComp) to it's parent and then again reflect the change in a different child component (ReflectiveComp).

        Home
      /      \
     /        \
    /          \
inputComp    ReflectiveComp

So in the template of inputComp i'm using the following input to get the data:

and in the script section of inputComp, i've added a watcher to listen to changes:

export default defineComponent({
  name: 'inputComp, ',
  data(){
      return{
          inputText: ''
      }
  },
  watch:{
      inputText: function(val, oldVal){
          this.$emit('change-input',val);
      }
  }
});

In the parent component (Home), highlight is the variable i want to pass into ReflectiveComp component:

<template>
      <inputComp @change-input="onChange"/>
      <ReflectiveComp :highlight="highlight"/>
</template>
<script>
export default defineComponent({
  components: { Countries, HighlightFilter },
  data(){
    return{
      highlight: 0
    }
  },
  methods:{
    onChange(val){
        this.highlight = val;
    }
  }
});
</script>

and in the ReflectiveComp:

<template>
        <label>{{highlight}}</label>
   </template>
        
   <script>
    
    import { defineComponent } from 'vue'
    
    export default defineComponent({
        name: 'ReflectiveComp',
        props:{
          highlight: Number
        },
    </script>

From the results i've been getting it seems that: the onChange method inside the parent component (Home) is being triggered and updated everytime we change the input in inputComp component.

The issue: the highlight vraiable is not changing in ReflictiveComp.

What am i doing wrong??

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