問題:使用uni-app開發過程中遇到一個需求,后台給出PDF預覽的鏈接,在手機上查看pdf文件
解決辦法:
showPdf: function(fileId) {
uni.downloadFile({
// 下面一行時拼接預覽PDF的地址!!!
url: this.$api.PDF_VIEW + fileId,
success: function(res) {
var filePath = res.tempFilePath;
if (!filePath) return
uni.openDocument({
filePath: filePath,
success: function(res) {
console.log(res);
console.log('打開文檔成功');
}
});
}
});
},
備注 api.js中配置預覽地址
PDF_VIEW: BaseUrl +'/api/file-manage/pdf-view?fileId=', // 展示pdf