Returning data from Axios API

前端 未结 8 1345
伪装坚强ぢ
伪装坚强ぢ 2020-12-07 11:52

I am trying to use a Node.JS application to make and receive API requests. It does a get request to another server using Axios with data it receives from an API call it rece

8条回答
  •  天涯浪人
    2020-12-07 12:49

    I made an empty array before calling the axios get and after .then(function(response)) pushed the necessary data in the array at the end of the function returned the array

    function axiosTest () {
         var strr = [];
            axios.get(url)
           .then(function(response){
                   strr.push(response.data);
            })
    
    
            .catch(function(error){
                   console.log(error);
               });
            return strr;
    }   
    

提交回复
热议问题