Here is the changed beforeUpload code:

beforeUpload(file) { let _this = this; // Make the returned value a Promise object, reject, reject, reject, reject Resolve return new Promise(function(resolve, reject){ _this.readexcel (file). Then (result => {// Const isLt2M = file.size / 1024/1024 < 2; if (! IsLt2M) {_this.$message.error(' File size cannot exceed 2MB! '); } if (isLt2M &&result){resolve(' check! '); } else { reject(false); $message.error();}}, error => {reject (); reject(false); }); }); }Copy the code

The following is the modified code for readExcel

ReadExcel (file) {// parse Excel let _this = this; Return new Promise(resolve, reject){const reader = new FileReader(); Var data = e.troge. result, workbook = xlsx.read (data, workbook = xlsx.read) {type: 'binary'}); } catch (e) { reject(e.message); } var fromTo = ''; For (var sheet in workbook.sheets) {let sheetInfos = workbook.sheets [sheet]; let locations = []; // A1,B1,C1... if (workbook.Sheets.hasOwnProperty(sheet)) { fromTo = sheetInfos['!ref']; // A1:B5 locations = _this.getLocationsKeys(fromTo); } for (let i = 0; i < locations.length; i++) { let value = sheetInfos[locations[i]].v; if (value ! Reject reject(locations[I] +'s parameter isn't '+ I); Resolve resolve(true); }}; reader.readAsBinaryString(file); }); }Copy the code

Here is the getLocationsKeys code

GetLocationsKeys (range) {A1:B5 output A1,B1... BA1 (BZ1) let rangeArr = range.split(':'); let startString = rangeArr[0]; let endString = rangeArr[1]; var reg=/[A-Z]{1,}/g; let end = endString.match(reg)[0]; let total = 0; For (let index = 0; index < end.length; index++) { total += Math.pow(26, end.length - index - 1) * (end.charCodeAt(index) - 64); } let result = []; for (let i = 0; i < total; i++) { result.push(this.getCharFromIndex(i) + '1'); } return result; },Copy the code