uni-app 微信小程序 pdf预览

<div @click="getPDF">查看体检报告</div>
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);
		}
	})
}

请添加图片描述

猜你喜欢

转载自blog.csdn.net/qq_36410795/article/details/134673029