axios的文件流blob

tech2026-08-28  1

web批量下载图片:web批量下载图片

updataZip(res, index) { let blob = new Blob([res], { type: 'application/zip' }) // window.location.href = window.URL.createObjectURL(blob); var zipName = index + '.zip'; // 下载的文件名 let link = document.createElement("a"); // 创建一个<a>标签 link.style.display = "none"; // 隐藏标签 link.href = window.URL.createObjectURL(blob); // 配置href link.download = zipName; link.click(); link.remove(); }, updataImg(item,name) { let blob = res.data; let id = 'img' + index; let src = window.URL.createObjectURL(blob); document.getElementById(id).src = src; this.picArr.push([key, src]) let zipName = name; // 下载的文件名 let link = document.createElement("a"); // 创建一个<a>标签 link.style.display = "none"; // 隐藏标签 link.href = item; // 配置href link.download = zipName; link.click(); link.remove(); }, 转换为JSON var reader = new FileReader(); reader.readAsText(new Blob([res.data])); reader.onload = e => { //判断接口是否返回失败信息 if(e.target.result.indexOf('message') !== -1) { this.dialogVisible = false; this.$message('获取失败,请重新操作!'); return; } }

13位时间戳

getTimestamp() { return new Date().getTime(); },

GUID32位小写

getMessageid() { return 'xxxxxxxxxxxx4xxxyxxxxxxxxxxxxxxx'.replace(/[xy]/g, function(c) { var r = Math.random()*16|0, v = c == 'x' ? r : (r&0x3|0x8); return v.toString(16); }); },

正则

json[key].match(/.zip+$/) JSON.stringify(imgList) != '{}' e.target.result.indexOf('message') !== -1
最新回复(0)