Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

244
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda