react 之中的post下载问题

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 = `
            
            `
            document.body.appendChild(form)
        }
        document.getElementById("exportForm").submit() 
    }

后端参数


fe665c873085c87da40c020faf652b3.png

你可能感兴趣的:(react 之中的post下载问题)