1. 上传文件
如iview中的:
<Upload action="" :before-upload="handleBeforeUpload" accept=".doc, .docx">
<Button :loading="uploadLoading">上传文件</Button>
</Upload>
2. 读取doc文件内容
先安装mammoth.js插件: npm i mammoth --save
引用: import * as mammoth from 'mammoth'
readFile (file) {
const reader = new FileReader()
reader.readAsArrayBuffer(file)
reader.onload = e => {
const data = reader.result
mammoth.extractRawText({arrayBuffer: data}).then(r=>{
console.log(r.value)
})
}
},