在uni-app中下载文件需要先获取文件的临时路径,然后再进行保存,才算下载成功:

// #ifdef APP-PLUS
				const downloadTask = uni.downloadFile({
						url: 'http://xxxxxxxx.com.cn/'+url, //仅为示例,并非真实的资源
							success: (res) => {
								if (res.statusCode === 200) {
									console.log('下载成功');
								}
								let that = this;
								uni.saveFile({
									tempFilePath: res.tempFilePath,
										success: function(red) {
											uni.openDocument({
												filePath:red.savedFilePath,
												success: (sus) => {
													console.log('成功打开')
												}
											})
											console.log(red)
										}
									});
								}
							})
							downloadTask.onProgressUpdate((res) => {
								console.log('下载进度' + res.progress);
								console.log('已经下载的数据长度' + res.totalBytesWritten);
								console.log('预期需要下载的数据总长度' + res.totalBytesExpectedToWrite);
						})
				//#endif
Logo

基于 Vue 的企业级 UI 组件库和中后台系统解决方案,为数万开发者服务。

更多推荐