vue下载文件重命名文件名称

const fileSetNameDown = (res,name) =>{
    let link = document.createElement("a");
    let fileName = decodeURIComponent(
      res.headers["content-disposition"].split("=")[1]
    );
    let ext = fileName.substring(fileName.lastIndexOf('.'));
    // 新建一个blob对象保证重命名文件成功
    var url = URL.createObjectURL(
       new Blob([res.data], {
        type: "application/x-download;charset=UTF-8",
      })
    );
    name ? link.download = name + ext : link.download = fileName + ext;
    link.href = url;
    link.click();
    return true;
}
上一篇:5、nacos启动项目报错Redis health check failed Unable to connect to localhost 6379


下一篇:二分