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

122
Visualizações
emit data from a router view to the App.vue

for a school project I have to build a vue js app.

I used emit and :v-on to exchange data and trigger methods from child component and it works great!, now I want to do the same thing from a child composant, that is a vue. That means it is a a component displayed by the router.

here is the child component:

methods: {
        logout () {
            console.log("logout child")
            this.$emit('logoutUser', this.user)
        }
},

and the app.vue:

<router-view v-if="this.user.isConnected && this.user.username != ''" :userProp="user" v-on:logout="logoutUser"></router-view>


[...]


logoutUser(user) {
            console.log("logout App.vue", user)
        }

I got the log from the child: "logout child", but I can't access the method logoutUser in App.vue... the "logout App.vue" log never show...

Do you know were I did a mistake? I'm pretty much a noob

Thanks!

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

0

You have to change your v-on:logout in the router-view element to v-on:logoutUser, the v-on has to have the same value the $emit has. Also you could shorten your code a little with using @ instead of v-on: (so @logoutUser="logoutUser")

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