word预览方式---插件,vue-office-docx、docx-preview、mammoth.js

提示:word预览方式---插件

### 文章目录

  • [@[TOC](文章目录)](#文章目录 @TOC 前言 一、vue-office-docx 二、docx-preview 三、mammoth.js 总结)
  • [前言](#文章目录 @TOC 前言 一、vue-office-docx 二、docx-preview 三、mammoth.js 总结)
  • [一、vue-office-docx](#文章目录 @TOC 前言 一、vue-office-docx 二、docx-preview 三、mammoth.js 总结)
  • [二、docx-preview](#文章目录 @TOC 前言 一、vue-office-docx 二、docx-preview 三、mammoth.js 总结)
  • [三、mammoth.js](#文章目录 @TOC 前言 一、vue-office-docx 二、docx-preview 三、mammoth.js 总结)
  • [总结](#文章目录 @TOC 前言 一、vue-office-docx 二、docx-preview 三、mammoth.js 总结)

前言

word预览

一、vue-office-docx

c 复制代码
npm install vue-office-docx -S-D

officeDocx.vue

c 复制代码
<template>
    <div class="preview_box">
      <VueOfficeDocx :src="htmlContent"></VueOfficeDocx>
    </div>
  </template>
  
  <script>
  import axios from 'axios'
  import VueOfficeDocx from '@vue-office/docx'
  //引入相关样式
  import '@vue-office/docx/lib/index.css';

  
  export default {
    name: 'preview',
    components:{VueOfficeDocx},
    data () {
      return {
        src:`.docx文件rul`,
        htmlContent:''
      }
    },
    mounted(){
      this.docToHtml();
    },
    methods: {
      docToHtml(){
        axios.get(this.src,{ responseType: 'arraybuffer' }).then((res)=>{
          this.htmlContent = res.data;
        })
      }
    }
  }
  </script>
  <style scoped></style>
  

样式还原度一般,间距太大,分页也有问题

二、docx-preview

c 复制代码
npm install docx-preview -S-D

docxPreview.vue

c 复制代码
<template>
    <div class="preview_box">
       <div ref="docxPreviewRef"></div>
    </div>
  </template>
  
  <script>
  import axios from 'axios'
  import { renderAsync }  from 'docx-preview'

  
  export default {
    name: 'preview',
    components:{},
    data () {
      return {
        src:`.docx文件rul`,
      }
    },
    mounted(){
      this.docToHtml();
    },
    methods: {
      docToHtml(){
        axios.get(this.src,{ responseType: 'arraybuffer' }).then((res)=>{
          renderAsync(res.data, this.$refs.docxPreviewRef);
        })
      }
    }
  }
  </script>
  <style scoped></style>
  

样式还原度一般,无分页

三、mammoth.js

c 复制代码
npm install mammoth.js -S-D

docxMammoth.vue

c 复制代码
<template>
    <div class="preview_box">
       <div ref="docxPreviewRef" v-html="htmlContent"></div>
    </div>
  </template>
  
  <script>
  import axios from 'axios'
  import mammoth  from 'mammoth'
  export default {
    name: 'preview',
    components:{},
    data () {
      return {
        src:`.docx文件rul`,
        htmlContent:''
      }
    },
    mounted(){
      this.docToHtml();
    },
    methods: {
      docToHtml(){
        axios.get(this.src,{ responseType: 'arraybuffer' }).then((res)=>{
          mammoth.convertToHtml({ arrayBuffer: new Uint8Array(res.data) }).then((html)=>{
            this.htmlContent = html.value;
          })
        })
      }
    }
  }
  </script>
  <style scoped></style>
  

样式有问题,表格都没了

总结

踩坑路漫漫长@~@

相关推荐
烛阴1 小时前
精简之道:TypeScript 参数属性 (Parameter Properties) 详解
前端·javascript·typescript
开发者小天2 小时前
为什么 /deep/ 现在不推荐使用?
前端·javascript·node.js
一枚小小程序员哈4 小时前
基于Vue的个人博客网站的设计与实现/基于node.js的博客系统的设计与实现#express框架、vscode
vue.js·node.js·express
找不到工作的菜鸟4 小时前
Three.js三大组件:场景(Scene)、相机(Camera)、渲染器(Renderer)
前端·javascript·html
定栓4 小时前
vue3入门-v-model、ref和reactive讲解
前端·javascript·vue.js
binqian5 小时前
【异步】js中异步的实现方式 async await /Promise / Generator
开发语言·前端·javascript
LIUENG5 小时前
Vue3 响应式原理
前端·vue.js
前端李二牛5 小时前
异步任务并发控制
前端·javascript
你也向往长安城吗6 小时前
推荐一个三维导航库:three-pathfinding-3d
javascript·算法
karrigan6 小时前
async/await 的优雅外衣下:Generator 的核心原理与 JavaScript 执行引擎的精细管理
javascript