vue 预览word

安装依赖 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>

猜你喜欢

转载自blog.csdn.net/qq_42181155/article/details/126729185