Appearance
- default
- chenghua
- shijingshan
- sybz
- gulou
无数据
Appearance
document-preview 通过 docx-preview 和 xlsx 在浏览器端渲染 Word、Excel 文件。使用 Word 或 Excel 预览功能时,请先在项目中安装依赖:
pnpm add docx-preview
pnpm add xlsxpnpm add docx-preview
pnpm add xlsxPDF 文件使用浏览器原生能力,通过 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 文件地址必须允许当前页面跨域请求。
| 属性 | 说明 | 类型 | 默认值 |
|---|---|---|---|
src | 文件地址,PDF 可直接预览 | string | 必填 |
type | 文件类型 | pdf / word / excel / auto | pdf |
width / height | 预览区域尺寸 | string / number | 100% / 600px |
download | 预览区域显示下载链接,点击后才下载 | boolean | true |