安装依赖 docx-preview
npm i docx-preview
<template>
<div class="home">
<div ref="file"></div>
</div>
</template>
<script>
import axios from 'axios'
let docx = require('docx-preview');
export default {
data() {
return {
docSrc: ""
}
},
mounted(){
this.preivewEvent();
},
methods: {
preivewEvent() {
axios({
method: 'get',
responseType: 'blob', // 设置响应文件格式
url: docSrc,
}).then(({data}) => {
docx.renderAsync(data,this.$refs.file) // 渲染到页面预览
})
},
}
}
</script>