title: Taro.openDocument(option)

sidebar_label: openDocument

新开页面打开文档,支持格式

支持情况:openDocument - 图1 openDocument - 图2 openDocument - 图3

参考文档

类型

  1. (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 pdf 格式

示例代码

  1. Taro.downloadFile({
  2. url: 'https://example.com/somefile.pdf',
  3. success: function (res) {
  4. var filePath = res.tempFilePath
  5. Taro.openDocument({
  6. filePath: filePath,
  7. success: function (res) {
  8. console.log('打开文档成功')
  9. }
  10. })
  11. }
  12. })