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

247
Visualizações
this.$emit is not a function inside file reader onload

I know about lexical scope that this keyword is pointing to the window and not Vue

But how do I make it point to Vue?

What I am trying to do is get csv data and parse it, I'm using d3 to parse the data it's working fine, I am just unable to emit the event with the data because of the scope issue

    async loadcsv(element){
        let reader = new FileReader();
        let file = element[0].file

        reader.onload =  async function (e){
            const data = e.target.result;
            let csvParsed = await d3.csvParse(reader.result);
            let collection = []
            csvParsed.forEach(function (element) {
                collection.push({
                    id: Math.floor(Math.random() * 10000000),
                    country : element['Country'],
                    email : element['Email id'],
                    poi_serial : element['Serial'],
                    status: "New"
                })
            });
            // Not working, shows it's not defined
            // this.$emit('csvCollection', collection) 
        }
        reader.readAsText(file);
    },
about 4 years ago · Santiago Gelvez
2 Respostas
Responde à pergunta

0

You can store the vue instance in a variable before the async function you are using like let self = this. or you can use an arrow function instead of the function you are using. see this similar question VueJs this.method is not a function? How to call a method inside another method in Vuejs?

about 4 years ago · Santiago Gelvez Relatório

0

change the reader.onload line to the below to keep lexical scope for the this keyword

reader.onload =  async (e) => {
about 4 years ago · Santiago Gelvez 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