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>

等数据接入再继续更新

相关推荐
莫物几秒前
element el-table表格 添加唯一标识
前端·javascript·vue.js
江上清风山间明月2 分钟前
使用python将markdown文件生成pdf文件
开发语言·python·pdf
vx_bisheyuange26 分钟前
基于SpringBoot的便利店信息管理系统
前端·javascript·vue.js·毕业设计
向下的大树1 小时前
Vue 2迁移Vue 3实战:从痛点到突破
前端·javascript·vue.js
老华带你飞1 小时前
工会管理|基于springboot 工会管理系统(源码+数据库+文档)
java·数据库·vue.js·spring boot·后端·spring
这儿有一堆花1 小时前
确保 PDF 真实性:数字签名与文档加固技术深度解析
pdf
前端OnTheRun2 小时前
如何禁用项目中的ESLint配置?
javascript·vue.js·eslint
打工人小夏2 小时前
vue3使用transition组件,实现过度动画
前端·vue.js·前端框架·css3
2501_930707782 小时前
使用C#代码将 Excel 转换为 ODS,或将 ODS 转换为 Excel
excel
仰望.2 小时前
vue 甘特图 vxe-gantt table 依赖线的使用,配置连接线
vue.js·甘特图