用的时候直接调用就行了
this.downloadAll(url)//url是下载文件的地址
//下载方法
downloadAll(url) {
wx.showLoading({
title: '下载中...',
})
wx.downloadFile({
url: url,
success: function (res) {
if (res.statusCode == 200) {
wx.hideLoading();
const filePath = res.tempFilePath
wx.openDocument({
filePath: filePath,
fileType: 'pdf',
showMenu: true,
success: function (res) {
console.log(res, "66666");
console.log('打开文档成功')
}
})
}
},
fail: function (err) {
console.log('fail')
console.log(err)
wx.showToast({
icon: 'none',
title: '下载文件失败'
});
}
})
},
原生小程序下载功能(直接复制用就行了)
于 2022-10-13 15:36:29 首次发布