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.