【问题标题】:How to Send a Raw Data Body to an Axios GETRequest in React Native?如何在 React Native 中向 Axios GETRequest 发送原始数据体?
【发布时间】:2021-12-20 17:23:27
【问题描述】:

我尝试从 GET API 获取数据但我不想获取所有记录,仅记录与我以 json 格式发送的原始数据中的参数匹配 我该如何在本机反应中做到这一点请帮助

const GetData = () => {
  axios({
      method: 'get',
      url: 'http://10.0.2.2:3000/DonarsRecod',
      data: {
        organ: "Lungs"
      }
    })
    .then(function(response) {
      console.log("response", JSON.stringify(response.data))
    })
    .catch(function(error) {
      console.log("error", error)
    })
}

【问题讨论】:

标签: node.js reactjs react-native


【解决方案1】:

代替body 使用params 获取HTTP 方法https://github.com/axios/axios#example

const GetData = () => {
  axios({
      method: 'get',
      url: 'http://10.0.2.2:3000/DonarsRecod',
      params: {
        organ: "Lungs"
      }
    })
    .then(function(response) {
      console.log("response", JSON.stringify(response.data))
    })
    .catch(function(error) {
      console.log("error", error)
    })
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-08-14
    • 1970-01-01
    • 2020-11-21
    • 2023-03-31
    • 2020-09-15
    • 1970-01-01
    • 2020-01-19
    • 2020-05-01
    相关资源
    最近更新 更多