1.关键点:
- blob
- 乱码
- 传参
2.参考资料:处理blob文件流和乱码问题
https://blog.csdn.net/qq_41512902/article/details/125680531
https://blog.csdn.net/qq_38804584/article/details/109238794
3.我的代码:axios发请求下载excel
js代码文章来源:https://www.toymoban.com/news/detail-516369.html
download_dlt_report(method,url,data,headers){
axios({
method: "post",
url: 'https://dltapi.wistron.com/dlt/skillcard/download', // 请求地址
data:{
"plantCode":"P1",
"currentPage": 1,
"pageSize": 10
},
headers:{
'Content-Type': 'application/json',
'Authorization': "Bearer ********************************************",
},
responseType: "blob" // 表明返回服务器返回的数据类型
// responseType: "arraybuffer",
}).then(
(response) => {
console.log('response',response)
let fileName = "skillcard" + Date.parse(new Date()) + ".xlsx";
if (window.navigator.msSaveOrOpenBlob) {
navigator.msSaveBlob(response, fileName);
} else {
let link = document.createElement("a");
link.href = window.URL.createObjectURL(new Blob([response.data],{type: "application/vnd.ms-excel"}));
link.download = fileName;
link.click();
window.URL.revokeObjectURL(link.href);
}
},
(err) => {
reject(err);
}
);
},
文章来源地址https://www.toymoban.com/news/detail-516369.html
到了这里,关于【Vue】axios发请求下载excel--20230630的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!