下载文件
var a = document.createElement('a')
var event = new MouseEvent('click')
a.download = item.fileName
a.href = item.photosUrl;
a.dispatchEvent(event)
但是有时候, a.download 会失效,可以使用 axios进行下载文件
axios.get(item.photosUrl, { responseType: "blob" }).then(response => {
const blob = new Blob([response.data]);
const link = document.createElement("a");
link.href = URL.createObjectURL(blob);
link.download = item.fileName;
link.click();
URL.revokeObjectURL(link.href);
}).catch(console.error);
网友评论