Vue 预览 Doc 文件:三种方法实现在线查看
Vue 本身不支持直接预览 doc 文件,需要借助第三方库或服务。以下是三种实现方式:
1. 使用 Office Online Viewer 插件
在 Vue 中嵌入 Office Online 预览器,可以通过以下代码实现:
<template>
<div>
<iframe
src='https://view.officeapps.live.com/op/embed.aspx?src=https://example.com/path/to/document.docx'
width='100%'
height='600px'
frameborder='0'
></iframe>
</div>
</template>
需要注意的是,该插件依赖 Office Online 服务,且需要提供 doc 文件的公开链接。
2. 使用 Google Docs Viewer 插件
在 Vue 中嵌入 Google Docs 预览器,可以通过以下代码实现:
<template>
<div>
<iframe
src='https://docs.google.com/gview?url=https://example.com/path/to/document.docx&embedded=true'
width='100%'
height='600px'
frameborder='0'
></iframe>
</div>
</template>
同样需要提供 doc 文件的公开链接。
3. 使用第三方插件 (vue-doc-preview)
可以通过引入 vue-doc-preview 插件来实现预览,代码如下:
<template>
<div>
<doc-preview
:src='https://example.com/path/to/document.docx'
:width='600'
:height='800'
></doc-preview>
</div>
</template>
需要在 Vue 项目中引入该插件,并传入 doc 文件的链接。
原文地址: https://www.cveoy.top/t/topic/n4Oy 著作权归作者所有。请勿转载和采集!