//地址转文件
changeBlob(){
return new Promise(resolve => {
const xhr = new XMLHttpRequest();
xhr.open('GET','文件地址', true);
xhr.responseType = 'blob';
xhr.onload = () => {
if (xhr.status === 200) {
resolve(xhr.response);
}
};
xhr.send();
});
},
//像接口一样调用
itemClick(){
this.changeBlob().then(res=>{
console.log(res)
this.saveAs(res,'文件名')
})
},
//下载文件
saveAs(blob, filename) {
var link = document.createElement('a');
link.href = window.URL.createObjectURL(blob);
link.download = filename;
link.click();
},