Home > Article > Web Front-end > What are the two ways to download files in react
The two ways to download files in react are:
Learning video sharing: react video tutorial
1, GET Type download
download = url => { const eleLink = document.createElement('a'); eleLink.style.display = 'none'; // eleLink.target = "_blank" eleLink.href = url; // eleLink.href = record; document.body.appendChild(eleLink); eleLink.click(); document.body.removeChild(eleLink); };
2, POST type download
static async download(params) { let form = document.createElement('form'); form.style.display = 'none'; form.action = `${api}tCmPaymentOrd/export`; form.method = 'POST'; document.body.appendChild(form); // 动态创建input并给value赋值 for (var key in params) { var input = document.createElement('input'); input.type = 'hidden'; input.name = key; input.value = params[key]; form.appendChild(input); } form.submit(); form.remove(); }
The above is the detailed content of What are the two ways to download files in react. For more information, please follow other related articles on the PHP Chinese website!