标签:click name win 下载文件 download down object bsp ==
获取下载文件的url
axios({
url: ‘xxxx‘,
data: {id:‘xxx‘},
headers:{token:‘xxx‘}
}).then(res => {
let url = res.data.url
downloadFile(url)
})
downloadFile(url){
var ajax = new XMLHttpRequest()
ajax.open(‘get‘,url)
ajax.responseType = ‘blob‘
ajax.setRequestHeader(‘token‘,‘xxxxx‘)
ajax.onload = () => {
if(ajax.status == 200){
console.log(ajax.response)
var fileName = ajax.responseURL.substring(ajax.responseURL.lastIndexof(‘/‘+1))
saveAs(fileName ,ajax.response)
}
}
}
saveAs(name,data){
var urlObject = window.URL;
var export_blob = new Blob([data])
var save_link = document.createElement(‘a‘)
save_link.href = urlObject.createObjectURL(export_blob)
save_link.download = name
save_link.click()
}
标签:click name win 下载文件 download down object bsp ==
原文地址:https://www.cnblogs.com/cuishuangshuang/p/13200938.html