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

240
Views
passing event.target.getAttribute() to data in Vue

HTML code:

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

and want to pass the src url of the image to data passing it through $event to a Vue method.

vue script code:

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

I also tried:

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

But it works with window.console.log and shows the correct URL, but if I try it to pass it to data(), its not working. No error, its just empty or undefined. What am I missing?

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

0

It looks like everything your are doing is correct:

check this stackblitz here: https://stackblitz.com/edit/vue-tu7vzx

So I guess it is really the question how you are trying to access this.imgurl

However, your question does not show enough code to make an educated guess.

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!