// 图片下载
downLoadImg(url, filename){
const a = document.createElement('a');
a.setAttribute('src', url);
//a标签的download属性 filename:规定被下载的超链接目标。
a.setAttribute('download', filename);
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
}
// excel下载
downLoad(data, filename) {
const BOM = '\uFEFF'; // 强制excel打开文件时使用 UTF-8
const blob = new Blob([BOM + data]); // 转换成blob对象
const a = document.createElement('a');
a.download = filename;
a.style.display = 'none';
a.href = URL.createObjectURL(blob);
document.body.appendChild(a);
a.click();
URL.revokeObjectURL(a.href); // 释放URL和<a />
document.body.removeChild(a);
}
利用 a 标签下载图片、excel
于 2021-11-24 17:52:51 首次发布