欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 文旅 > 八卦 > vue2/3 中使用 @vue-office/docx 在网页中预览(docx、excel、pdf)文件

vue2/3 中使用 @vue-office/docx 在网页中预览(docx、excel、pdf)文件

2025/5/13 7:53:22 来源:https://blog.csdn.net/snow_living/article/details/147896034  浏览:    关键词:vue2/3 中使用 @vue-office/docx 在网页中预览(docx、excel、pdf)文件

1. 安装依赖:

#docx文档预览组件
npm install @vue-office/docx vue-demi@0.14.6
#excel文档预览组件
npm install @vue-office/excel vue-demi@0.14.6
#pdf文档预览组件
npm install @vue-office/pdf vue-demi@0.14.6

vue2.6版本或以下还需要额外安装 @vue/composition-api

npm install @vue/composition-api

vue2中在components文件中写个组件

<template><div><vue-office-docx v-if="type == 'docx'" :src="`${matchType(src)}`" @rendered="rendered" /><vue-office-excel v-if="type == 'excel'" :src="`${matchType(src)}`" @rendered="rendered" /><vue-office-pdf v-if="type == 'pdf'" :src="`${matchType(src)}`" @rendered="rendered" /></div></template><script>
import VueOfficeDocx from '@vue-office/docx';
import VueOfficeExcel from '@vue-office/excel';
import VueOfficePdf from '@vue-office/pdf';
export default {components: {VueOfficeDocx,VueOfficeExcel,VueOfficePdf},props: {src: {type: String,required: true},},data() {return {type: docx}},methods: {matchType(fileName) {// 后缀获取var suffix = ''// 获取类型结果var result = ''try {var flieArr = fileName.split('.')suffix = flieArr[flieArr.length - 1]} catch (err) {suffix = ''} }}}
</script><style></style>

 等数据接入再继续更新 

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

热搜词