function axgetdata(url,params){
axios({
method: ‘get’,
url: url,
params: params,
responseType: ‘blob’
}).then((res) => {

const link = document.createElement('a')
let blob = new Blob([res.data],{type: 'application/vnd.ms-excel'});
//获取heads中的filename文件名
let temp = res.headers["content-disposition"].split(";")[1].split("filename=")[1];
//对文件名乱码转义--【Node.js】使用iconv-lite解决中文乱码
let iconv = require('iconv-lite'); 
iconv.skipDecodeWarning = true;//忽略警告
let fileName = iconv.decode(temp, 'gbk');
console.log('fileName_',fileName)
// return
link.style.display = 'none'
link.href = URL.createObjectURL(blob);
link.setAttribute('download', fileName)
document.body.appendChild(link)
link.click()
document.body.removeChild(link)
}).catch(error => {
       //console.log(error);
});

相关文章:

  • 2021-12-17
  • 2021-12-17
  • 2022-02-01
  • 2021-11-23
  • 2021-09-07
  • 2022-03-06
  • 2021-10-19
  • 2022-12-23
猜你喜欢
相关资源
相似解决方案