关键要点:responseType: “blob”,
this.$axios({
url: "/api/device/deviceInfo/createDeviceInfoByExcel",
method: "post",
headers: {
"Content-Type": "multipart/form-data",
token: localStorage.getItem("token"),
},
data: formData,
responseType: "blob",//关键点
}).then((res) => {
console.log(res);
//下载文件操作
const link = document.createElement("a");
let blob = new Blob([res.data], {
type: "application/vnd.ms-excel" });//生成blob对象
console.log(blob)
link.style.display = "none";
link.href = URL.createObjectURL(blob);
link.setAttribute("download", "冲突设备" + ".xls"); //下载的文件名以及文件格式
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
});