1.下载插件docx-preview
cnpm i docx-preview --save
2.后台请求接口拿到文档流(res.dat), 并调用docx-previre的方法渲染文件到页面
<template>
<div>
<el-button @click="createpsbgDoc">报告</el-button>
<div ref="word" class="docWrap"></div>
</div>
</template>
<script>
import axios from 'axios';
var docxx = require("docx-preview");
export default {
methods:{
createpsbgDoc() {
axios({
url: "http://10.8.214.46:8088/monitor/test",
method: 'get',
data: {},
responseType: "arraybuffer"
}).then(res => {
docxx.renderAsync(res.data, this.$refs.word);
}).catch((error) => {
console.log(接口)
});
},
}
}
</script>
参考文档:https://blog.csdn.net/weixin_45294459/article/details/126997364