uni.downloadFile({
			url: 'xx 请求地址,
			header: {
			 'token': token  //token 获取
			},
			success: (res) => {
					if (res.statusCode === 200) {
							var filePath = res.tempFilePath;
							uni.saveFile({
							    tempFilePath: filePath,
								success: function(saveRes) {
								const savedFilePath = saveRes.savedFilePath
								// 下载成功后,你可以进行一些处理,比如保存文件路径或打开文件等
										uni.openDocument({
											filePath: savedFilePath,
											success: function() {
												console.log('打开文档成功')
											}
										})
									},
									fail: function(failRes) {
										console.log('保存文件失败:', failRes.errMsg);
									}
								});
							}
						}
			    });

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐