a标签下载的两种方法
1、<a href="/files/文件.zip">下载1</a>
2、
<div @click="download">下载2</div>
download(){
let url = '/files/文件.zip'
let filename = '下载的文件名称'
return fetch(url).then(res => res.blob().then(blob => {
let a = document.createElement('a');
let url = window.URL.createObjectURL(blob);
console.log(url);
a.href = url;
a.download = filename;
a.click();
window.URL.revokeObjectURL(url);
}))
}
转载自:https://segmentfault.com/a/1190000041600899