Company logo
  • Empleos
  • Bootcamp
  • Acerca de nosotros
  • Para profesionales
    • Inicio
    • Empleos
    • Cursos y retos
    • Preguntas
    • Profesores
    • Bootcamp
  • Para empresas
    • Inicio
    • Nuestro proceso
    • Planes
    • Pruebas
    • Nómina
    • Blog
    • Calculadora

0

40
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?

7 months ago · Juan Pablo Isaza
3 Respuestas
Responde la pregunta

0

Try to add the native modifier :

@click.native="isClickable ? doSomeStuff : null"
7 months 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() }
}
7 months 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" />
7 months 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 empleo Planes Nuestro proceso Comercial
Legal
Términos y condiciones Política de privacidad
© 2023 PeakU Inc. All Rights Reserved.