<input type="file" accept=".xlsx, .xls" @change="changeFile" />
js 代码
// 文件上传
changeFile(ev) {
// console.log('file: ', ev.target.files[0]);
let f = ev.target.files[0],
reader = new FileReader();
reader.onload = (e) => {
let data = e.target.result;
// console.log('data: ', data);
let wb = XLSX.read(data, { type: 'array' });
// console.log('wb: ', wb);
this.$refs.demo.innerHTML = JSON.stringify( XLSX.utils.sheet_to_json(wb.Sheets[wb.SheetNames[0]]) );
let jsonData = XLSX.utils.sheet_to_json(wb.Sheets[wb.SheetNames[0]]);
// console.log('jsonData: ', jsonData);
}
reader.readAsArrayBuffer(f)
},