I have been trying to convert excel file to Json and the problem is that when I want to add this data to an array in the component’s data , I am unable to do that.
I tried to see what is happening in the console , and the component’s data is changed to proxy object.
here’s my data :
data(){
return {
arr: [],
};
},
here’s my function :
onChange(event) {
var input = event.target;
var reader = new FileReader();
reader.readAsBinaryString(input.files[0]);
reader.onload = () => {
var fileData = reader.result;
var wb = XLSX.read(fileData, {type : 'binary'});
wb.SheetNames.forEach((sheetName) => {
var rowObj =XLSX.utils.sheet_to_json(wb.Sheets[sheetName]);
for(const item of rowObj) {
this.arr.push(item);
}
})
console.log(this.arr);
};
},
doing console.log(this.arr[1]) or any number outside the onload function will result in an undefined message.