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

242
Views
pasando event.target.getAttribute() a datos en Vue

Código HTML:

 <img src="images/website/image.svg" alt="" width="150px" height="150px" v-on:click="submitimage($event)">

y desea pasar la url src de la imagen a los datos pasándolos a través de $event a un método Vue.

código de secuencia de comandos vue:

 <script> export default { data(){ return { imgurl: '' } }, methods: { submitimage(event){ var element = event.target; var id = element.getAttribute('src'); window.console.log(id) this.imgurl = id }, }, } </script>

También probé:

 methods: { submitimage(event){ this.imgurl = this.event.target.getAttribute('src'); window.console.log(event.target.getAttribute('src')) },

Pero funciona con window.console.log y muestra la URL correcta, pero si intento pasarlo a data(), no funciona. No hay error, simplemente está vacío o indefinido. ¿Qué me estoy perdiendo?

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

0

Parece que todo lo que estás haciendo es correcto:

revisa este stackblitz aquí: https://stackblitz.com/edit/vue-tu7vzx

Así que supongo que es realmente la cuestión de cómo estás tratando de acceder a this.imgurl

Sin embargo, su pregunta no muestra suficiente código para hacer una conjetura.

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!