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 = `<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
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容