downloadItem({
url: 'https://***/api/resource/202302021031533311478.xlsx',
name: '舞阳1.xlsx'
})
downloadItem(file) {
// 下载名称为前端自定义名称
const url = window.URL.createObjectURL(new Blob([file.url], {
type: 'application/vnd.ms-excel;charset=UTF-8'
}));
const link = document.createElement('a');
link.href = url;
link.setAttribute('download', file.name); // 下载文件的名称及文件类型后缀
document.body.appendChild(link);
link.click();
document.body.removeChild(link); // 下载完成移除元素
window.URL.revokeObjectURL(url); // 释放掉blob对象
// 下载名称为后端生成的名称
// const val = file.url // 部署环境下载地址
// var a = document.createElement('a')
// a.href = val
// a.click()
// 或
// window.location.href = file.url
},
前端下载线上文件自定义文件名称
最新推荐文章于 2024-06-26 16:30:27 发布