W3Cschool
恭喜您成為首批注冊用戶
獲得88經(jīng)驗(yàn)值獎(jiǎng)勵(lì)
解釋:新開頁面打開文檔,支持格式:doc, xls, ppt, pdf, docx, xlsx, pptx。
Web 態(tài)說明: Web 態(tài)只支持在部分瀏覽器環(huán)境下打開 pdf 格式文檔,其他情形會(huì)觸發(fā) fail 回調(diào)。
Object object
屬性名 | 類型 | 必填 | 默認(rèn)值 | 說明 |
---|---|---|---|---|
filePath | String | 是 | 文件路徑,可通過 downloadFile 獲得 | |
fileType | String | 否 | 文件類型,指定文件類型打開文件,有效值 doc, xls, ppt, pdf, docx, xlsx, pptx。 | |
success | Function | 否 | 接口調(diào)用成功的回調(diào)函數(shù) | |
fail | Function | 否 | 接口調(diào)用失敗的回調(diào)函數(shù) | |
complete | Function | 否 | 接口調(diào)用結(jié)束的回調(diào)函數(shù)(調(diào)用成功、失敗都會(huì)執(zhí)行) |
<view class="wrap">
<view class="card-area">
<view class="display-area">
<image class="display-area-image" src="https://b.bdstatic.com/searchbox/icms/searchbox/img/file-pdf.png" rel="external nofollow" mode="widthFix"></image>
<view class="title">示例文件.pdf</view>
</view>
<button type="primary" bindtap="openDocument">打開文件</button>
</view>
</view>
Page({
openDocument() {
swan.downloadFile({
url: 'https://example.com/file/xxx', // 僅為示例,并非真實(shí)的接口地址
success: res => {
swan.openDocument({
filePath: res.tempFilePath,
fileType: 'pdf',
success: res => {
console.log('openDocument success', res);
},
fail: err => {
console.log('openDocument fail', err);
}
});
},
fail: err => {
console.log('downloadFile fail', err);
}
});
}
});
錯(cuò)誤碼 | 說明 |
---|---|
202 | 解析失敗,請檢查參數(shù)是否正確 |
1001 | 執(zhí)行失敗 |
錯(cuò)誤碼 | 說明 |
---|---|
202 | 解析失敗,請檢查參數(shù)是否正確 |
2001 | 文件不存在 |
2005 | 文件格式不支持 |
Copyright©2021 w3cschool編程獅|閩ICP備15016281號(hào)-3|閩公網(wǎng)安備35020302033924號(hào)
違法和不良信息舉報(bào)電話:173-0602-2364|舉報(bào)郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號(hào)
聯(lián)系方式:
更多建議: