react中使用GET或POST方法下载文件

GET方法

window.location.href = `${serviceUrl()}/um-mall-service/orders/export`;

若需要带参数,直接在url后面拼接参数。

POST方法

onUploadData(params) { 
   const formElement = document.createElement('form'); 
   formElement.style.display = 'display:none;'; 
   formElement.method = 'post';
   formElement.action = `${serviceUrl()}/um-mall-service/orders/export`; 
   formElement.target = 'callBackTarget';  
   const inputElement = document.createElement('input');  
   inputElement.type = 'hidden';  
   inputElement.name = 'params';  
   inputElement.value = params; 
   formElement.appendChild(inputElement);  
   document.body.appendChild(formElement); 
   formElement.submit();  
   document.body.removeChild(formElement);  
 }

你可能感兴趣的:(react)