// 预览pdf
const previewPdf = (url, pageTitle) => {
Taro.showLoading({ title: '加载中...' });
const link = encodeURIComponent(url);
if (config.platform !== 'android') {
Taro.hideLoading();
return Taro.navigateTo({
url: `/pages/webview/index?url=${link}&title=${pageTitle}`
});
}
Taro.downloadFile({
url: url,
success: result => {
const { tempFilePath } = result;
Taro.openDocument({
filePath: tempFilePath,
success: () => {
Taro.hideLoading();
},
fail: res => {
Taro.hideLoading();
Taro.showModal({ content: res.errMsg });
}
});
},
fail: res => {
Taro.hideLoading();
Taro.showModal({ content: res.errMsg });
}
});
};
Taro 小程序常用的预览H5或者PDF函数
于 2022-05-10 10:45:07 首次发布