uniapp 跨平台 H5 小程序 文件下载

目前写的是一个兼容H5与小程序的项目。大多数内容还是可以比较完美的兼容的。但是到了下载文件这里就出了点问题。
uni.downloadFile虽然是可以兼容小程序和H5,但是uni.saveFile是不支持的。
这里就把两端分开写了。uniapp 跨平台 H5 小程序 文件下载_第1张图片

HTML

									
									下载入口
									
									
									
									下载入口
									

JS

			/**
			 * 下载到本地
			 */
			downLoad: function(id) {
				uni.downloadFile({
					url: 'http://xxxxxxxxxx?id=' + id, //仅为示例,并非真实的资源
					success: (e) => {
						if (e.statusCode === 200) {
							let tempFilePaths = e.tempFilePath;
							console.log('地址', tempFilePaths)
							/*注意:saveFile 会把临时文件移动,因此调用成功后传入的 tempFilePath 将不可用。*/
							uni.saveFile({
								tempFilePath: tempFilePaths,
								complete: (res) => {
									var savedFilePath = res.savedFilePath;
									console.log(savedFilePath);
									uni.showToast({
										title: '保存成功',
										icon: 'none'
									})
								}
							});
						}
					}
				});
			},

你可能感兴趣的:(小程序,H5,uniapp)