Nhảy tới nội dung

my.openDocument

openDocument

my.openDocument là API dùng để xem trước file PDF.

Quét mã để trải nghiệm

Xem code mẫu trên Tini Studio

Demo

Trải nghiệm thử với trình giả lập bên dưới

API Params

Thuộc tínhKiểu dữ liệuBắt buộcMô tả
filePathStringĐường dẫn thông qua kết quả trả về của my.downloadFile.
fileTypeStringĐịnh dạng file.
successFunctionCallback function khi open document được thực hiện thành công.
failFunctionCallback function khi open document thất bại.
completeFunctionCallback function khi việc open document kết thúc cho dù thành công hay thất bại.
Giá trịMô tả
pdfĐịnh dạng PDF

Sample Code

<view>
<block-header title="Usage" description="File system" />
<view class="block-content">
<input class="input-full" onInput="onChangeUrl" value={{urlFile}} placeholder="Input File Url to Open"></input>
<button class="button-full" onTap="onOpenDocument">Open Document</button>
</view>
</view>
Page({
data: {
urlFile: ''
},
onOpenDocument() {
my.showLoading({ content: 'Loading...' });
my.downloadFile({
url: this.data.urlFile,
success: (res) => {
my.openDocument({
filePath: res.filePath, // only for mobile
fileType: 'pdf',
url: this.data.urlFile // only for web
success: (res) => {
console.log('open document success');
my.hideLoading();
},
fail: (e) => {
console.log('open document fail');
my.hideLoading();
}
});
},
fail: (e) => {
my.hideLoading();
}
});
},
onChangeUrl(e) {
this.setData({ urlFile: e.detail.value });
}
});