微信小程序打开pdf
wxml
<block
wx:for="{{list}}"
wx:key="id"
wx:for-item="item"
wx:for-index="index">
<view class="list_item" bindtap="downLoadPDF" data-url="{{item.filePath}}">
<view class="item_name">
{{item.title}}
</view>
<view class="item_date">
{{item.publishDate}}
</view>
</view>
</block>
js
//下载PDF文件
downLoadPDF(e){
let url = e.currentTarget.dataset.url;
// wx.showModal({
// title: '温馨提示',
// content: '确认要打开此PDF文件吗?',
// showCancel: true,
// cancelText: '取消',
// confirmText: '确定',
// success: (result) => {
// if (result.confirm) {
wx.downloadFile({
url: url,
success: function (resinfo) {
console.log("pdf协议文件已下载")
let path = resinfo.tempFilePath;
console.log(path, resinfo)
wx.openDocument({
filePath: path,
fileType: 'pdf',
success: function (rest) {
console.log('打开文件成功')
console.log(rest);
},
fail: function (error) {
wx.showToast({
icon: 'none',
title: '打开文件失败'
});
},
})
},
fail: function (err) {
console.log('fail')
console.log(err)
wx.showToast({
icon: 'none',
title: '下载文件失败'
});
}
})
// }
// },
// fail: () => {},
// complete: () => {}
// })
},
分类:
微信小程序
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· winform 绘制太阳,地球,月球 运作规律
· AI与.NET技术实操系列(五):向量存储与相似性搜索在 .NET 中的实现
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 上周热点回顾(3.3-3.9)
2022-09-19 送给自己和大家的三句话