let url = res.data.fileUrl
if(that.systemInfo.platform =='windows'){
uni.downloadFile({
url: url,
filePath: `wxfile://temp/list.xlsx`,
success: function (res) {
that.tempUrl = res.tempFilePath
var filePath = res.tempFilePath;
wx.saveFileToDisk({
filePath: filePath,
success: function (res) {
that.$toast('保存成功')
}
})
}
});
}else {
uni.downloadFile({
url: url,
success: function (res) {
that.tempUrl = res.tempFilePath
var filePath = res.tempFilePath;
uni.openDocument({
filePath: filePath,
showMenu:true,
success: function (res) {
// console.log('打开文档成功');
}
});
}
});
}
小程序下载文件
本文介绍了一种在不同平台上实现文件下载及打开的方法。针对Windows平台,文章详细讲解了如何使用uni.downloadFile进行文件下载,并将其保存到本地磁盘。对于非Windows平台,则展示了如何直接打开下载的文件。


被折叠的 条评论
为什么被折叠?



