Vue axios 下载 excel文件

153 阅读1分钟
downLoadFile(data.fileId)
        .then(res => {
          const blob = new Blob([res], {
            type: "application/vnd.ms-excel"
          });
          const fileName = data.fileName;
          if (window.navigator.msSaveOrOpenBlob) {
            navigator.msSaveBlob(blob, fileName);
          } else {
            var link = document.createElement("a");
            link.href = window.URL.createObjectURL(blob);
            link.download = fileName;
            link.click();
            // 释放内存
            window.URL.revokeObjectURL(link.href);
          }
        })
        .catch(() => {});
}
    ```