下载文件并修改下载文件名称

downloadFile (filePath,fileName) {
  const url = window.URL.createObjectURL(new Blob([filePath], {
    type: 'application/vnd.ms-excel;charset=UTF-8'
  }));
  const link = document.createElement('a');
  link.href = url;
  link.setAttribute('download', fileName); // 下载文件的名称及文件类型后缀
  document.body.appendChild(link);
  link.click();
  document.body.removeChild(link); // 下载完成移除元素
  window.URL.revokeObjectURL(url); // 释放掉blob对象
}    
调用
this.downloadFile('http://pubdev.****.com/orderImportData/85506b9a-3371-ac67-5b24-d46564d23c44.xlsx','运单导入模板-测试.xlsx') 

 

posted @ 2021-10-12 10:18  wyy_wdy  阅读(752)  评论(0编辑  收藏  举报