1.安装插件 npm install --save mammoth
2.引入插件 import mammoth from "mammoth"
// 3.根据文件地址请求后端返回文件流arraybuffer类型
lookFj(query) {
return axios.get(`${baseUrl.apiUrl}/train/queryAnnex?` + qs.stringify(query), {
responseType: 'arraybuffer'
})
},
// 4.文件流通过插件转换为html格式
lookFj(accessUrl) {
var vm = this;
this.$request.lookFj({
path: accessUrl
}).then(res=> {
mammoth
.convertToHtml(
{ arrayBuffer: new Uint8Array(res)}
)
.then(function (resultObject) {
vm.$nextTick(() => {
vm.content = resultObject.value;
});
});
}).catch(err=> {
})
},
// 5.展示在页面
<div class="content" v-html="content"></div>