想在vue中预览doxc,excel,pdf文件? vue-office提供包支持

在浩瀚的Vue生态中,vue-office犹如一颗璀璨的星辰,以其独特的魅力照亮了开发者处理多种文件格式的预览之路。这款精心打造的Vue组件库,不仅拥抱了Vue2的经典,也紧密跟随Vue3的步伐,展现了卓越的技术前瞻性和兼容性。它巧妙地集成了对DOCX、Excel、PDF等多种文件格式的支持,让文档预览在Web应用中变得前所未有的便捷与高效。

使用实例:轻盈如风,预览无界

想象一下,在您的Vue项目中,只需简单几行代码,即可将复杂的文档预览功能嵌入其中。无论是用户上传的简历、项目报告,还是财务报表,vue-office都能以优雅的方式呈现,让信息的传递与共享变得直观而流畅。无需担心文件格式的兼容性问题,vue-office以其强大的解析能力,确保每种文档都能精准还原,让用户享受如原生应用般的预览体验。

vue-office(git地址https://github.com/501351981/vue-office)

安装

#docx文档预览组件

npm install @vue-office/docx vue-demi

#excel文档预览组件

npm install @vue-office/excel vue-demi

#pdf文档预览组件

npm install @vue-office/pdf vue-demi

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

npm install @vue/composition-api/

vue3+Typescript格式

本地excel文件预览
TypeScript 复制代码
<template>
    <vue-office-excel
         src="/assets/ComputerIT.pdf"
          @rendered="renderedHandler"
          @error="errorHandler"
          class="excel-viewer"
    />
</template>

<script lang="ts" setup>
import VueOfficeExcel from '@vue-office/excel'
function renderedHandler() {
  console.log("渲染完成");
}

function errorHandler() {
  console.log("渲染失败");
}
</script>
本地word 文件预览
TypeScript 复制代码
<template>
    <vue-office-docx
          src="/assets/ComputerIT.pdf"
          @rendered="renderedHandler"
          @error="errorHandler"
          class="docx-viewer"
    />
</template>

<script lang="ts" setup>
import VueOfficeDocx from '@vue-office/docx'
function renderedHandler() {
  console.log("渲染完成");
}

function errorHandler() {
  console.log("渲染失败");
}
</script>
本地pdf 文件预览
TypeScript 复制代码
<template>
    <vue-office-pdf
          src="/assets/ComputerIT.pdf"
          @rendered="renderedHandler"
          @error="errorHandler"
          class="pdf-viewer"
    />
</template>

<script lang="ts" setup>
import VueOfficePdf from '@vue-office/pdf'
function renderedHandler() {
  console.log("渲染完成");
}

function errorHandler() {
  console.log("渲染失败");
}
</script>
相关推荐
_codemonster12 小时前
Vue中的ref和reactive到底在干嘛
前端·javascript·vue.js
葡萄城技术团队17 小时前
为什么很多企业最终都会重新评估“自研 Excel”的成本?
excel
前端fighter17 小时前
线上崩溃?使用 TRAE Work 5分钟把混淆日志翻译成人话并输出复盘报告
前端·vue.js·程序员
常宇佳17 小时前
vue3 实战系列之无法识别vue组件
前端·javascript·vue.js
daols8818 小时前
vue 实现基于 vxe-table 构建多维度产品对比表
前端·javascript·vue.js
AI刀刀20 小时前
能生成 word 文档的文心在导出时易出现排版错乱,AI 导出鸭精准优化版式,提升文档完整性
人工智能·c#·word·excel·ai导出鸭
mashirro21 小时前
记一次基于ruoyi-vue新增小程序服务模块,小程序登陆相关
vue.js·小程序·mybatis
SpaceAIGlobal21 小时前
AI PPT生成工具哪些支持PDF文档导入?
人工智能·ai·pdf·powerpoint·办公
Xxtaoaooo1 天前
极空间部署Stirling PDF:搭建自托管PDF工具箱并实现远程访问
pdf·cpolar·stirling pdf
常宇佳1 天前
vue3 $refs使用方法
前端·vue.js·typescript