Skip to main content
Version: 2.x

Taro.openDocument(option)

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

参考文档

类型

(option: Option) => Promise<CallbackResult>

参数

Option

参数类型必填说明
filePathstring文件路径,可通过 downloadFile 获得
complete(res: CallbackResult) => void接口调用结束的回调函数(调用成功、失败都会执行)
fail(res: CallbackResult) => void接口调用失败的回调函数
fileType"doc" | "docx" | "xls" | "xlsx" | "ppt" | "pptx" | "pdf"文件类型,指定文件类型打开文件
success(res: CallbackResult) => void接口调用成功的回调函数

fileType

文件类型

参数说明
docdoc 格式
docxdocx 格式
xlsxls 格式
xlsxxlsx 格式
pptppt 格式
pptxpptx 格式
pdfpdf 格式

示例代码

Taro.downloadFile({
url: 'https://example.com/somefile.pdf',
success: function (res) {
var filePath = res.tempFilePath
Taro.openDocument({
filePath: filePath,
success: function (res) {
console.log('打开文档成功')
}
})
}
})

API 支持度

API微信小程序H5React Native
Taro.openDocument✔️