【问题标题】:Post data onto different APIs in React JS from a single form using axios使用 axios 从单个表单将数据发布到 React JS 中的不同 API
【发布时间】:2021-12-09 01:46:30
【问题描述】:

例如。我想将姓名和电子邮件发布到 API 中,并将它们的地址发布到来自同一个 .js 文件的不同 API 中。 我应该如何解决这个问题。

【问题讨论】:

  • 添加您的示例代码。您可以从一个组件调用任意数量的 API 调用。我们需要看到您的实现才能更完美地回答
  • 请提供足够的代码,以便其他人更好地理解或重现问题。

标签: node.js reactjs api post axios


【解决方案1】:

创建一个函数并将您想要通过 api 发送的值传递给它,然后在您的函数体内创建任意数量的 api 调用。 在ES6:

const myFunction = (name, email, address) => {
    axios.post('apiString1', {name, email}).then(response => {console.log(response)});
    axios.post('apiString2', {address}).then(response => {console.log(response)});
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-06-14
    • 1970-01-01
    • 1970-01-01
    • 2023-02-04
    • 2020-02-05
    • 2014-07-21
    • 2017-06-05
    • 2020-09-07
    相关资源
    最近更新 更多