Update child component method VueJS

0

I'm trying to update a method of a child component, but so far I have had no solution, my question is as follows.

Within Header.vue , I display the pending hours

<span>
    <b>{{Hours}}</b> horas pendentes
</span>

    hours(){                
  axios.get('http://localhost:83/Pendencia/HorasPendentes/${this.$localStorage.get('RecursoId')}')
    .then(res => {
    this.Hours = res.data.Retorno
  })
    .catch(err => console.log(err))
}

Now in my file Pendencia.vue , I find a API , and in return of this API called in Pendencia.vue would like to call API of Header.vue again.

    
asked by anonymous 13.03.2018 / 14:40

1 answer

1

You can use $children to find a child component and thus access all your data , methods , etc.

Try to create as follows:

const componenteFilho = this.$children.find(component => component.$options.name === "Nome_do_componente_filho");

componenteFilho.funcao_da_Api()

Then use this in method , mounted or somehow better for you;)

    
13.03.2018 / 14:55