iso打开没有下载,安卓打开有下载:
<view class='pdf_box' catchtap='downLoadPdf' data-url="https://baidu.pdf">
<image src='../../images/pdf.png' mode='widthFix'></image>
<label>下载资源</label>
</view>
JS:
downLoadPdf(e){
var url = e.currentTarget.dataset.url;
wx.showToast({
title: '打开中…',
icon: "loading",
duration: 100000
})
if (url){
wx.downloadFile({
url: url,
header: {
'content-type': 'application/json',
},
// filePath: wx.env.USER_DATA_PATH + "/res",
success: function (res) {
console.log(res)
var Path = res.tempFilePath //返回的文件临时地址,用于后面打开本地预览所用
wx.openDocument({
filePath: Path,
success: function (res) {
wx.hideToast();
}
})
},
fail: function (res) {
console.log(res);
wx.showToast({
title: '下载失败',
icon: "loading",
duration: 1000
})
}
})
}
},