简体   繁体   English

如何在URL中发送带有URL的参数?

[英]How send parameters with URL in react?

I send a parameter with this 我用这个发送参数

apiUrl = SERVER_API_URL + '/api/import/estimatee/' + this.state.estimateId;
.post(apiUrl, formData, config)

but I need to send parameters like 但我需要发送像

apiUrl = SERVER_API_URL + '/api/import/estimatee/' + this.state.estimateId + this.state.purchaseOrder.purchaseOrderName + this.state.purchaseOrder.purchaseOrderCurr

How can I solve this Thanks for your feedback people? 我该如何解决?感谢您的反馈。

Use template literals with query parameters ? 使用带有查询参数的template literals ? and & to include multiple parameters: &包含多个参数:

const { estimateId, purchaseOrderCurr, purchaseOrderName } = this.state;

const apiURL = `${SERVER_API_URL}/api/import/estimate/order?estimateId=${estimateId}&purchaseOrderName=${purchaseOrderName}&purchaseOrderCurr=${purchaseOrderCurr}`

apiUrl will now be: apiUrl现在将是:

http://serverapi/api/import/estimate/order?estimateId="1234"&purchaseOrderName="orderName"&purchaseOrderCurr="USD"

Then you can use axios to post to apiUrl : 然后,您可以使用axios postapiUrl

axios.post(apiUrl, formData, config);

OR 要么

just paste the parameters in axios's options -- these parameters should be appended to formData , especially if they are relevant to what's being submitted in formData : 只需将参数粘贴到axios的options - 这些参数应附加到formData ,尤其是当它们与formData中提交的内容formData

const { estimateId, purchaseOrderCurr, purchaseOrderName } = this.state;

axios.post(`${SERVER_API_URL}/api/import/estimate`, { formData, estimateId, purchaseOrderCurr, purchaseOrderName }, config);

OR

const fd = new FormData();
fd.append('estimateId', estimateId);
fd.append('purchaseOrderCurr', purchaseOrderCurr);
fd.append('purchaseOrderName', purchaseOrderName);
...other formData options

axios.post(`${SERVER_API_URL}/api/import/estimate`, fd, config);
const { estimateId, purchaseOrderName } = this.state;
const apiUrl = `${SERVER_API_URL}/api/import/estimate/${estimateId}/${purchaseOrderName}`;

im solved this way thanks guys. 我通过这种方式解决了,谢谢大家。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM