vue中实现下载文件功能
最近在学习vue开发的过程中用到了问价下载,该博客只作为自己的学习笔记。
·
axios.get(url, { responseType: 'blob', }).then(response => { const url = window.URL.createObjectURL(new Blob([response.data])); const link = document.createElement('a'); Link.style.display = "none"; let fname = '考勤导入模版.xlsx'; link.href = url; link.setAttribute('download', fname); document.body.appendChild(link); link.click(); document.body.removeChild(Link); //下载完成移除元素 window.URL.revokeObjectURL(url); }).catch(error => { console.log('error:' + JSON.stringify(error)) });
axiost(
method: 'get',
url: url, // 请求地址
data: options, // 参数
responseType: 'blob' // 表明返回服务器返回的数据类型
).then(response => {
const url = window.URL.createObjectURL(new Blob([response.data]));
const link = document.createElement('a');
Link.style.display = "none";
let fname = '考勤导入模版.xlsx';
link.href = url;
link.setAttribute('download', fname);
document.body.appendChild(link);
link.click();
document.body.removeChild(Link); //下载完成移除元素
window.URL.revokeObjectURL(url);
}).catch(error => {
console.log('error:' + JSON.stringify(error))
});
更多推荐
已为社区贡献1条内容
所有评论(0)