23 lines
586 B
TypeScript
23 lines
586 B
TypeScript
![]() |
import axios from "axios";
|
||
|
|
||
|
const downloadPhoto = (imgSrc:any) => {
|
||
|
axios({
|
||
|
url: imgSrc,
|
||
|
method: 'get',
|
||
|
headers: { 'Content-Type': 'application/json' },
|
||
|
responseType: 'blob',
|
||
|
}).then(res => {
|
||
|
const url = window.URL.createObjectURL(res.data);
|
||
|
const a = document.createElement('a');
|
||
|
a.href = url;
|
||
|
a.download = '下载图片.jpg';
|
||
|
document.body.appendChild(a);
|
||
|
a.click();
|
||
|
document.body.removeChild(a);
|
||
|
window.URL.revokeObjectURL(url);
|
||
|
}).catch(error => {
|
||
|
console.error('Download error:', error);
|
||
|
});
|
||
|
};
|
||
|
|
||
|
export { downloadPhoto };
|