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

172
Visualizações
Vue JS emit event to child component from parent component not triggering

I'm working in a Nuxt JS project. I have several components, and one of my components called ComplianceOptoutRawText includes a child component called ComplianceOptoutViaExternalService, and it's this child component where I'm using a v-on to listen for an $emit event from the ComplianceOptoutRawText so I can toggle a variable, but I'm not seeing it at all in my console logs and need to know what I'm doing wrong and need to change.

Here's my markup with everything that's appropriate:

ComplianceOptoutRawText

<template>
  <div>
    <div>
      <div class="tw-hidden md:tw-block tw-font-bold tw-mb-4">
        <ComplianceOptoutViaExternalService>
          <template #trigger>
            <button @click="$emit('shown-optout-intent', true)" type="button">here</button>
          </template>
        </ComplianceOptoutViaExternalService>
      </div>
    </div>
  </div>
</template>

And then the child component itself:

ComplianceOptoutViaExternalService

<template>
  <div>
    <slot name="trigger"></slot>
    <article v-show="wantsToOptOut" v-on:shown-optout-intent="hasShownOptoutIntent" class="tw-bg-white tw-p-4 md:tw-p-6 tw-rounded-xl tw-text-gray-800 tw-border tw-border-gray-300 tw-text-left tw-mt-4">
      <validation-observer v-if="!didOptOut" ref="optoutServiceForm" key="optoutServiceForm" v-slot="{ handleSubmit }" tag="section">
        <form>
          ...
        </form>
      </validation-observer>
    </article>
  </div>
</template>

<script>
export default {
  data () {
    return {
      wantsToOptOut: false,
      isOptingOut: false,
      didOptOut: false
    }
  },
  methods: {

    /*
    ** User has shown opt out intent
    */
    hasShownOptoutIntent (value) {
      this.wantsToOptOut = !this.wantsToOptOut
    }

  }
}
</script>

Note that my child component uses a slot, this is so I can position everything as needed in the parent component, but at it's core, I have a parent component emitting a value and then listening for it via v-on:shown-optout-intent="hasShownOptoutIntent" which runs the hasShownOptoutIntent method.

But I never see anything from the button, even if I console.log this. What am I missing?

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

0

I'm doing something similar with an embedded component, so it's perhaps worth trying:

<button @click="$emit('update:shown-optout-intent', true)" type="button">here</button>

... and then:

v-on:shown-optout-intent.sync="hasShownOptoutIntent"

As an aside, it's safe to remove v-on and use: :shown-optout-intent.

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