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>

等数据接入再继续更新

相关推荐
Non-existent9877 小时前
WPS批量清理单元格空白字符的4种方法-异常数字格式处理-实战
excel·wps
奋斗吧程序媛7 小时前
补充一个小知识点:有关@click.native
前端·vue.js
英勇无比的消炎药8 小时前
一行命令背后:TinyRobot CLI 如何重构 AI 对话接入的效率范式
vue.js·aigc
weixin_397574098 小时前
PDF复杂表格的1:1还原引擎:跨页表格自动拼接技术实战
大数据·人工智能·pdf
Metaphor6929 小时前
使用 Python 将 PDF 转换为 HTML
python·pdf·html
2601_961845159 小时前
粉笔行测5000题电子版|pdf|解析
pdf·新媒体运营·github·个人开发·内容运营·规格说明书·极限编程
jay神10 小时前
基于 FastAPI + Vue 的宠物领养管理系统
前端·vue.js·python·毕业设计·fastapi·宠物
一杯奶茶¥10 小时前
水果销售网站 CRM客户信息管理系统 超市管理系 酒店管理系统 健身房管理系统 在线音乐网站 校园招聘系统
java·vue.js·spring boot·mysql·spring·java项目
英勇无比的消炎药10 小时前
一站式搞定品牌风格:TinyRobot 主题定制从入门到精通
vue.js
Sour10 小时前
PDF翻译卡住不动怎么办?扫描件、OCR 和大文件排查清单
前端·pdf·ocr