html
<div @click="getPDF">查看体检报告</div>
js
getPDF() {
uni.downloadFile({
url: `${this.$baseURL}/file/download?id=${this.pdfFileId}`,//编写在线的pdf地址
success: function(res) {
const filePath = res.tempFilePath;
uni.openDocument({
filePath: filePath,
fileType: 'pdf',//这里类型必须是pdf
success: function(res) {
console.log('打开PDF成功');
},
fail: function(res) {
console.log('打开PDF失败', res);
}
})
},
fail: function(res) {
console.log('下载PDF失败', res);
}
})
}