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

166
Visualizações
Vue how to add click event to <nuxt-img>

In my vue-app I need to make a <nuxt-img />-clickable, so I tried to do this:

<nuxt-img :src="image.src" @click="isClickable ? doSomeStuff : null" />

but for some reason I don't know, this is not working - nothing happens on click.

Can someone tell me what I'm doing wrong?

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

0

Try to add the native modifier :

@click.native="isClickable ? doSomeStuff : null"
about 4 years ago · Juan Pablo Isaza Relatório

0

I would pass a function there, like somebody already suggested in the comments:

@click="() => isClickable ? doSomeStuff : null"

but better would be to enclose the logic in a method and call the method @click="handleClick"

...
methods: {
  handleClick(){
    if(this.isClickable){ this.doSomeStuff() }
}
about 4 years ago · Juan Pablo Isaza Relatório

0

<nuxt-img :src="image.src" @click="isClickable ? doSomeStuff : null" />

doSomeStuff has to be defined as a function in order to be called like that

Otherwise you should call it with a thunk

For instance:

<nuxt-img :src="image.src" @click="isClickable ? () => doSomeStuff : null" />

Still I would give an undefined to the @onclick event instead of a null value

<nuxt-img :src="image.src" @click="isClickable ? () => doSomeStuff : undefined" />
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