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

531
Views
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
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!