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

javascript 复制代码
npm install @vue/composition-api

vue2中在components文件中写个组件

html 复制代码
<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>

等数据接入再继续更新

相关推荐
2301_322414280418 小时前
活力孕康复APP 47737- 原创(免费领源码+部署教程+开发环境)
java·vue.js·spring boot·mysql·微信小程序·idea·微信开发者工具
专业程序开发源20 小时前
springbootLivehouse票务系统-计算机课程设计、毕业设计
vue.js·spring boot·后端·python·django·课程设计·pygame
leoZ23120 小时前
2026-09-10-静态扫描连错三次-用运行环境当裁判
前端·javascript·vue.js·人工智能·opencv·机器学习·数据挖掘
卓怡学长20 小时前
w233基于vue和springboot的宠物管理系统的设计与实现
java·vue.js·spring boot·spring·intellij-idea
张彦峰ZYF1 天前
从“全量 OCR”到按页智能路由:pdf-inspector 与企业 PDF 解析架构的工程化重构
人工智能·pdf·ocr·ai agent·pdf-inspector
梨涡泥窝1 天前
JavaWeb——基于 Spring Boot + Vue 的图书管理系统的设计与实现
vue.js·spring boot·后端
鲲穹AI种草1 天前
Excel 表格批量处理与数据整理,多款表格工具能力客观记录
excel·表格处理
SamChan901 天前
Python批量处理PDF踩坑实录:中文编码、字体内嵌、多栏排版与内存占用
python·单片机·ai·pdf·机器翻译
huali1 天前
vue-split-screen:让 Vue Router 的导航轨迹变成两个页面
前端·javascript·vue.js
cspttty1 天前
2026秋招供应链分析师技能栈:SQL、Excel、BI与业务分析
数据库·sql·excel