Get
如果是get地址的话,直接window.open(url)打开就行了。
Post
1、网上通用的用法
image.png
image.png
image.png
转载:https://www.cnblogs.com/wujiaxing/p/15090200.html
问题: 返回的excel文件里面只有一个[Object Object]显示
解决:
这里就要用到post的第二种下载方式了,那就是利用form表单去下载,target设置为blank
const exportData=()=>{
let params ={
customerName:customerNameValue?customerNameValue:"",
parentManage:parentManageValue?parentManageValue:"",
intlManage:intlManageValue?intlManageValue:"",
}
if (document.getElementById("exportForm")) {
document.getElementById("customerName").value = params.customerName;
document.getElementById("parentManage").value = params.parentManage;
document.getElementById("intlManage").value = params.intlManag;
}else{
let form = document.createElement(`form`);
form.id = "exportForm"
form.style = "display:none;";
form.method = 'post';
form.action = "/iportal/controller/inoc/queryExport";
form.target = "_blank";
form.innerHTML = `<input type="hidden" value="${params.customerName}" name="customerName" id="customerName"/>
<input type="hidden" value="${params.parentManage}" name="parentManage" id="parentManage"/>
<input type="hidden" value="${params.intlManage}" name="intlManage" id="intlManage"/>`
document.body.appendChild(form)
}
document.getElementById("exportForm").submit()
}
后端参数
fe665c873085c87da40c020faf652b3.png