1 html
<Button @click="imFile.click()" type="primary" :loading="excelLoading" style="margin-right: 5px;" v-if="importClassIsShow">导入Excel</Button>
<input type="file" @change="importFile(this)" id="imFile" style="display: none"
accept="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.ms-excel"/>
2 script
const XLSX = require('xlsx');
imFile: '',
mounted() {
this.imFile = document.getElementById('imFile');
},
importFile() {// 导入excel
let obj = this.imFile;
if (!obj.files) return;
this.excelLoading = true;
let f = obj.files[0], reader = new FileReader(), _this = this;
reader.onload = async function (e) {
let data = e.target.result;
if (_this.rABS) {
_this.wb = XLSX.read(btoa(this.fixdata(data)