js文件下载自定义命名
js下载文件时,如果下载地址文件名与实际名称不一致,需要自定义命名,使用a链接时如果涉及跨域,download属性不生效,解决方法:
通过axios请求文件,创建a链接下载即可。
axios.get(file_path,{responseType:'blob'}).then(res=>{
const blob=new Blob([res.data])
const link=document.createElement('a')
link.href=URL.createObjectURL(blob)
link.download=fileName
link.click()
URL.revokeObjectURL(link.href)
})

浙公网安备 33010602011771号