图片下载
This commit is contained in:
parent
16bc099987
commit
d0207e5a08
23
src/api/download/index.ts
Normal file
23
src/api/download/index.ts
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
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 };
|
Loading…
Reference in New Issue
Block a user