vue前端上传doc文件并读取文件内容
1. 上传文件如iview中的:<Uploadaction="":before-upload="handleBeforeUpload"accept=".doc,.docx"><Button:loading="uploadLoading">上传文件</Button></Upload>2. 读取文件
·
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)
})
}
},
更多推荐
已为社区贡献3条内容
所有评论(0)