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

76
Visualizações
Add click event

I wanna ask about click event in Vue. I have a span contain div and button. When I click on the button (thisButton) it works well, but the span (thisMask) doesn't seem to work when it clicked. I also add emit event and when I clicked on thisButton it also trigger emit event thisMaskClicked. But the console.log just return which thisButton has. Did I miss something?

<span class="this_mask" @click="thisMask">
  <div class="this__wrap">
    <div class="this__text">
      <button class="this__button" @click="thisButton"></button>
    </div>
  </div>
</span>

this.js

thisMask () {
  this.$emit('thisMaskClicked')
  console.log("This Mask Executed")
},
thisButton() {
  this.$emit('thisButtonClicked')
  console.log("This Button Clicked")
}
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

What you are looking for is the self modifier.

If a parent node and child node are registered with same type of event then when that type event dispatches then handlers of parent and child are called.

Here is an example fiddle

Your code should look like:

<span class="this_mask" @click="thisMask">
  <div class="this__wrap">
    <div class="this__text">
      <button class="this__button" @click.self="thisButton"></button>
    </div>
  </div>
</span>

Code is untested so I'm not sure if you have to attach in your example to button or span

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