在小程序上预览文件,并且有加载动画
let downloadTask = wx.downloadFile({ //下载
url: https://xxxxx...., //服务器上的地址
success: function (res) {
var filePath = res.tempFilePath
wx.openDocument({ //打开
filePath: filePath,
success: function (res) {}
})
}
})
downloadTask.onProgressUpdate((res) => {
if (res.progress === 100) {
wx.hideLoading()
return
} else {
wx.showLoading({
title: `正在进入...${res.progress}%`,
})
}
})
本文介绍了如何在微信小程序中使用`wx.downloadFile`下载文件,并通过`onProgressUpdate`实现下载过程中的加载动画效果,以及随后通过`wx.openDocument`预览文件。
1万+





