Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

164
Views
Vue cómo agregar un evento de clic a <nuxt-img>

En mi aplicación vue , necesito hacer un <nuxt-img /> en el que se pueda hacer clic, así que traté de hacer esto:

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

pero por alguna razón que no sé, esto no funciona, no sucede nada al hacer clic.

¿Alguien puede decirme qué estoy haciendo mal?

about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

Intenta agregar el modificador native :

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

0

Pasaría una función allí, como alguien ya sugirió en los comentarios:

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

pero sería mejor encerrar la lógica en un método y llamar al método @click="handleClick"

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

0

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

doSomeStuff tiene que ser definido como una función para ser llamado así

De lo contrario, deberías llamarlo con un golpe

Por ejemplo:

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

Aún así, le daría un valor indefinido al evento @onclick en lugar de un valor nulo

 <nuxt-img :src="image.src" @click="isClickable ? () => doSomeStuff : undefined" />
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!