Vue前端文件下载

async downloadFile(index) {
			try {
				if (true) {
					
					// 构造要下载的文件URL
					const fileUrl =this.report.fileUrls[index]
						// "http://aes.aes-iot.com:8301/file/img/06a07e11-e0d0-4fe1-bae2-086acbf11674.3.jpg"; // 替换为实际要下载的文件URL

					// var suffix = fileUrl.substring(fileUrl.lastIndexOf("."));
					// 创建一个a标签
					let response = await fetch(fileUrl);
					// 内容转变成blob地址
					let blob = await response.blob();
					// 创建隐藏的可下载链接
					let objectUrl = window.URL.createObjectURL(blob);
					let a = document.createElement("a");
					//地址
					a.href = objectUrl;
					//修改文件名
					a.download = this.report.fileNames[index];
					// 触发点击
					document.body.appendChild(a);
					a.click();
					//移除
					setTimeout(() => document.body.removeChild(a), 1000);
				}
			} catch (error) {
				console.error(error);
			} finally {
			}
		},

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值