- //下载文件到客户端
- //url:服务端地址
- function download(url){
- const xhr = new XMLHttpRequest();
- xhr.open('GET',url)
- xhr.responseType = 'blob'
- xhr.send()
- xhr.onload = function(){
- const fileBlob = xhr.response;
- console.log(fileBlob)
- const fileUrl = URL.createObjectURL(fileBlob)
- console.log(fileUrl)
- const elementA = document.createElement('a')
- elementA.setAttribute('href',fileUrl)
- elementA.setAttribute('download','')
- elementA.click()
- }
- }
复制代码 |