我以此发送参数
apiUrl = SERVER_API_URL + '/api/import/estimatee/' + this.state.estimateId;
.post(apiUrl, formData, config)
但是我需要发送
之类的参数apiUrl = SERVER_API_URL + '/api/import/estimatee/' + this.state.estimateId + this.state.purchaseOrder.purchaseOrderName + this.state.purchaseOrder.purchaseOrderCurr
我该如何解决?谢谢您的反馈?
答案 0 :(得分:2)
将template literals
与查询参数?
和&
一起使用以包含多个参数:
const { estimateId, purchaseOrderCurr, purchaseOrderName } = this.state;
const apiURL = `${SERVER_API_URL}/api/import/estimate/order?estimateId=${estimateId}&purchaseOrderName=${purchaseOrderName}&purchaseOrderCurr=${purchaseOrderCurr}`
apiUrl
现在将是:
http://serverapi/api/import/estimate/order?estimateId="1234"&purchaseOrderName="orderName"&purchaseOrderCurr="USD"
然后您可以使用axios
到post
到apiUrl
:
axios.post(apiUrl, formData, config);
OR
只需将参数粘贴到axios的options
中-这些参数应附加到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);
答案 1 :(得分:0)
const { estimateId, purchaseOrderName } = this.state;
const apiUrl = `${SERVER_API_URL}/api/import/estimate/${estimateId}/${purchaseOrderName}`;
我通过这种方式解决了,谢谢。