Skip to content
On this page

document-preview 文档预览组件 ​

使用说明 ​

document-preview 通过 docx-preview 和 xlsx 在浏览器端渲染 Word、Excel 文件。使用 Word 或 Excel 预览功能时,请先在项目中安装依赖:

bash
pnpm add docx-preview
pnpm add xlsx
pnpm add docx-preview
pnpm add xlsx

PDF 文件使用浏览器原生能力,通过 iframe 预览;Word 文件会先通过 fetch 获取文件内容,再交给 docx-preview 渲染。因此,Word 文件地址必须允许当前页面跨域请求(配置正确的 CORS 响应头),并且文件服务需要支持 GET 请求。无法在线预览时,组件会显示下载文件入口。

组件会根据 type 选择预览方式:默认值为 pdf,但文件扩展名为 .doc/.docx/.xls/.xlsx/.xlsm 时会自动使用对应渲染;也可以显式传入 type="auto"、type="pdf"、type="word" 或 type="excel"。Word 和 Excel 文件地址必须允许当前页面跨域请求。

基础用法 ​

本地pdf ​

本地word ​

测试 ​

属性 ​

属性说明类型默认值
src文件地址,PDF 可直接预览string必填
type文件类型pdf / word / excel / autopdf
width / height预览区域尺寸string / number100% / 600px
download预览区域显示下载链接,点击后才下载booleantrue

本地excel ​

思云博智私有前端组件库