react下载文件的两种方式分别是:
学习视频分享:react视频教程
1、GET类型下载
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类型下载
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(); }
Atas ialah kandungan terperinci react下载文件有哪两种方式. Untuk maklumat lanjut, sila ikut artikel berkaitan lain di laman web China PHP!