<button bindtap="download">下載</button>
download:function(){
wx.showLoading({
title: '正在下載...',
})
wx.downloadFile({
url: 'http://192.168.0.143:8080/mock/2021%E5%B9%B4%E5%85%AC%E5%8F%B8%E6%98%A5%E8%8A%82%E6%94%BE%E5%81%87%E8%B0%83%E4%BC%91%E9%80%9A%E7%9F%A5.pdf',
filePath: wx.env.USER_DATA_PATH + '/2021年公司春節放假調休通知.pdf',
success: function(res) {
wx.openDocument({
filePath: res.filePath,
success: function (res) {
wx.hideLoading()
console.log('打開文檔成功')
}
})
},fail: function(res){
console.log(res)
}
})
},
如果是用uniapp
uni.downloadFile({
url: xxx.pdf',
success: function (res) {
var filePath = res.tempFilePath;
uni.openDocument({
filePath: filePath,
success: function (res) {
console.log('打開文檔成功');
}
});
}
});