Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

163
Vistas
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 Respuestas
Responde la pregunta

0

Try to add the native modifier :

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

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda