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

532
Visualizações
How to upload local json file and save content into a variable Javascript?

So I want to upload a JSON file and save it's content into a variable. I wrote the following code:

<input type="file" id="file" ref="fileSelect" class="custom-file-input" @change="previewFiles" />

previewFiles() { 
    let files = this.$refs.fileSelect.files
    var reader = new FileReader();
    reader.onload = onReaderLoad;
    reader.readAsText(files[0]);  

    function onReaderLoad(event){
        //console.log(event.target.result);
        let json = JSON.parse(event.target.result);
        this.t = json       
    }
}

Basically, I am working with vue, so I want to store the local JSON file into the variable t so that I can use it in other places. Currently nothing is getting stored in t. I tried various other solutions but nothing is working. My end goal is to display this json's content as a table on another page and also use its content in other functions as well. I am new to javascript so any suggestions will be appreciated.

about 4 years ago · Juan Pablo Isaza
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