I'm trying to use ExcelJS in Vue and I need FileReader to read and parse the files but I'm getting errors. How do I use FileReader with VueJS?
Input Form
<input type="file"
id="importProductionSchedule"
name="importProductionSchedule"
@change="checkFile($event)"
ref="importProductionSchedule"
>
checkFile method
checkFile() {
let reader = new FileReader()
let self = this
reader.onload = (e) => {
let bstr = e.target.result
let wb = XLSX.read(bstr, {type:'binary'})
let wsname = wb.SheetNames[0]
let ws = wb.Sheets[wsname]
let data = XLSX.utils.sheet_to_json(ws, {header:1})
self.form.filedata = data
self.cols = make_cols(ws['!ref'])
}
reader.onerror = (stuff) => {
console.log("error", stuff)
console.log (stuff.getMessage())
}
// reader.readAsArrayBuffer(event)
reader.readAsBinaryString(event.target.files[0])
},
First of all, logging event.target.files[0] in the console would return the file, but I'm testing both event and event.target.files[0] to make sure.
These are my errors:
event = Uncaught Error: cannot read as File: {"isTrusted":true}
event.target.files[0] = Uncaught Error: cannot read as File: {}
checkFile(event) {...reader.readAsBinaryString(line, you get correct info about your file?v-on:syntax, not@syntax.