1.npm安装插件
npm i docx-preview
2.代码
<template>
<div>
<div ref="word"></div>
<span
@click="contractShowed()"
>预览合同</span>
</div>
</template>
<script>
import Axios from "axios";
let docx = require('docx-preview'); //引入插件
export default {
methods: {
getPdfCode (url) {
Axios ({
method: 'get',
responseType: 'blob',
url: url,
}).then(({data}) => {
docx.renderAsync(data,this.$refs.word) // 渲染到页面
})
},
contractShowed(){
this.getPdfCode('https:********.docx')
}
}
</script>
注意:url为文档路径