朋友们,今天工作碰到要实现下载文件,这个之前没写过,怎么实现的呀,是后端写好的接口,调接口就可以实现了嘛
后端写接口,前端发请求就可以了
后端写好接口 axios下载
downloadFile(url, filename) {
axios({
url: url,
method: 'GET',
responseType: 'blob',
}).then(response => {
const url = window.URL.createObjectURL(new Blob([response.data]));
const link = document.createElement('a');
link.href = url;
link.setAttribute('download', filename);
document.body.appendChild(link);
link.click();
});
}
性能优化是一个非常令人愉悦的过程,同时也是个深坑,有着太多东西,本篇文章开了个头,希望能对大家有所帮助,也欢迎大家一起交流~