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;
}
标签:重命名,vue,name,res,fileName,download,link,文件名称,let 来源: https://www.cnblogs.com/Azune/p/15901250.html