1、直接下载
window.open(url)
2、用fetch获取文件,a标签下载
fetch(url, {
method,
headers: {"token":token}
}).then((response) => {
response.blob().then(blob => {
let blobUrl = window.URL.createObjectURL(blob);
let aElement = document.getElementById('downloadDiv'); //获取a标签元素
let filename = 'test.mp4';//设置文件名称
aElement.href = blobUrl;//设置a标签路径
aElement.download = filename;
aElement.click();
window.URL.revokeObjectURL(blobUrl);
});
}).catch((error) => {
console.log(error)
alert('文件下载失败');
});