简体   繁体   English

Axios的get方法不起作用

[英]Axios get method is not working

I am just calling the api get using reactJS and axios. 我只是在调用使用reactJS和axios的api。 The api call is going but I'm unable to get the response from the server. api调用正在进行,但我无法从服务器获得响应。

Here is my code: 这是我的代码:

getProjectdetails(details) {
  alert("coming")
  details.map(function(project, i) {
    var projectId = project.projectId
    axios.get('http://workpresso.rankworld.io/api/v1/project?query={"projectId":"' + projectId + '"}', {
        params: {},
        headers: {
          "x-access-token": sessionStorage.token
        },
      })
      .then(function(response1) {}.bind(this))
      .catch(function(error) {
        console.log(error);
      });
  })
}

You'll need to return something from the then(). 您需要从then()返回一些内容。 If you want to avoid binding 'this' you can use an arrow function (if es6 is available, assuming you're using Node, it probably is). 如果要避免绑定“ this”,则可以使用箭头功能(如果es6可用,并且假设您正在使用Node,那么它可能是)。 Lastly, a map function transforms the array elements, so you need to return something in that function too. 最后,地图函数会转换数组元素,因此您也需要在该函数中返回一些内容。

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

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