vue2 安装 npm install -save mammoth.js ---word转换html插件
html代码 用的vue ant-design-vue
<a-upload name="file" accept=".pdf,.doc,.docx" :before-upload="beforeUpload">
<a-button>
<a-icon type="upload" /> 选择 </a-button>
</a-upload>
import mammoth from 'mammoth';
beforeUpload(file){
if (!file) {
return;
}
console.log(file+"input")
let fileType = ['.docx','.doc']
let { name } = file;
let nameLen = name.length;
let hzIndex = name.lastIndexOf(".");
//获取后缀名
let hz = name.substring(hzIndex, nameLen);
if (!fileType.includes(hz)) {
this.$message.warning({
message: "注意:只支持docx格式的文档",
})
return false
}
console.log(hz);
var that = this;
var reader = new FileReader();
reader.readAsArrayBuffer(file);
reader.onload = function (loadEvent) {
console.log(loadEvent.target.result);
var arrayBuffer = loadEvent.target.result;
mammoth.convertToHtml({ arrayBuffer: arrayBuffer })
.then(
function (resultObject) {
setTimeout(function(){
that.agreeContent = resultObject.value
}, 300);
console.log(resultObject.value);//这个就是我们得到的html
}).done();
};
},
本文转载自: https://blog.csdn.net/lx6091543wwwcctv/article/details/134093217
版权归原作者 Cola-blog 所有, 如有侵权,请联系我们删除。
版权归原作者 Cola-blog 所有, 如有侵权,请联系我们删除。