28 lines
615 B
TypeScript
28 lines
615 B
TypeScript
|
export const downloadBlob = (blob: Blob, name: string) => {
|
||
|
// 创建一个下载链接并模拟点击
|
||
|
const url = URL.createObjectURL(blob);
|
||
|
const a = document.createElement('a');
|
||
|
a.href = url;
|
||
|
a.download = name;
|
||
|
document.body.appendChild(a);
|
||
|
a.click();
|
||
|
|
||
|
// 清理
|
||
|
document.body.removeChild(a);
|
||
|
URL.revokeObjectURL(url);
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* 导出图像
|
||
|
* @param uri
|
||
|
* @param name
|
||
|
*/
|
||
|
export function downloadURI(uri: string, name: string) {
|
||
|
const link = document.createElement('a');
|
||
|
link.download = name;
|
||
|
link.href = uri;
|
||
|
document.body.appendChild(link);
|
||
|
link.click();
|
||
|
document.body.removeChild(link);
|
||
|
}
|