title: Taro.openDocument(option)
sidebar_label: openDocument
新开页面打开文档,支持格式
支持情况:
.default})
类型
(option: Option) => Promise<TaroGeneral.CallbackResult>
参数
| 参数 | 类型 |
|---|---|
| option | Option |
Option
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
| filePath | string |
是 | 文件路径,可通过 downloadFile 获得 |
| showMenu | boolean |
否 | 是否显示右上角菜单 |
| complete | (res: TaroGeneral.CallbackResult) => void |
否 | 接口调用结束的回调函数(调用成功、失败都会执行) |
| fail | (res: TaroGeneral.CallbackResult) => void |
否 | 接口调用失败的回调函数 |
| fileType | keyof FileType |
否 | 文件类型,指定文件类型打开文件 |
| success | (res: TaroGeneral.CallbackResult) => void |
否 | 接口调用成功的回调函数 |
FileType
文件类型
| 参数 | 说明 |
|---|---|
| doc | doc 格式 |
| docx | docx 格式 |
| xls | xls 格式 |
| xlsx | xlsx 格式 |
| ppt | ppt 格式 |
| pptx | pptx 格式 |
| pdf 格式 |
示例代码
Taro.downloadFile({url: 'https://example.com/somefile.pdf',success: function (res) {var filePath = res.tempFilePathTaro.openDocument({filePath: filePath,success: function (res) {console.log('打开文档成功')}})}})
