Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

527
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda