1. 引用t mammoth(先install)
import mammoth from "mammoth";
2.上传文件后,处理文件
getReferenceContent(result) {let text = result.value;// 将解析出部分文本const number= text.indexOf(xxx:");if(number>0){let content=text.substring(number+5,text.length-1);this.referenceContent=content;} },readFileInputEventAsArrayBuffer() {let that = this;var file = this.fileInfo.file;var reader = new FileReader();reader.onload = function (loadEvent) {console.log(loadEvent);var arrayBuffer = loadEvent.target.result; mammoth.extractRawText({ arrayBuffer: arrayBuffer }) .then(res => that.getReferenceContent(res));};reader.readAsArrayBuffer(file);}