需求:在小程序中显示PDF文件
思路:wx.openDocument打开新的网页,显示PDF文件
<view @click="showPdf">点击查看协议</view>
showPdf() {
// let url = otption.currentTarget.dataset.index.keyValue;
let url =
"https://fs.mufengweilai.com/api/gym/2024/01/22/84f266eafdc945ac8e55f84da1693687.pdf";
//打开pdf文件
wx.showLoading({
title: "加载中...",
});
wx.downloadFile({
url: url,
success: function (res) {
const filePath = res.tempFilePath;
wx.openDocument({
filePath: filePath,
success: function (res) {
wx.hideLoading();
},
fail: function (res) {
console.log("打开失败");
},
});
},
});
},