Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

271
Visualizações
Mutiple Axios return not able to return the value but in cosole it is coming

Multiple Axios return not able to return the value but in console it is coming first function is able to return the data> second and 3rd is not able to do>

< the first function is able to return the data> <the second and 3rd is not able to do>

async getdata() {
  let url = `xxxxxxxx`;
  this.axiosConfig = {
    withCredentials: false,
    maxRedirects: 3
  };
  let config: AxiosRequestConfig = { ...this.axiosConfig
  };
  //axios.defaults.headers.common = { 'Authorization': 'Bearer ' + this.token }
  var result = await axios.get(url, config);
  console.log(result.data); // --------------> data is coming here
  return result.data; //------------>able to return the data from here
}
async getfame() {
  var res = await this.getdata()
  res.map(async(item: any) => {
    let url = `xxxxxxxx`;
    this.axiosConfig = {
      withCredentials: false,
      maxRedirects: 3
    };
    let config: AxiosRequestConfig = { ...this.axiosConfig
    };
    //axios.defaults.headers.common = { 'Authorization': 'Bearer ' + this.token }
    var result1 = await axios.get(url, config);
    console.log(result1.data); // -----------------> data coming here
    return result1.data; //------------> not able to return the data from here
    //return axios.get<string>(url, config);
  })
}
async getfix() {
  var res1 = await this.getdata()
  res1.map(async(item: any) => {
    let url = `xxxxxxxx`;
    this.axiosConfig = {
      withCredentials: false,
      maxRedirects: 3
    };
    let config: AxiosRequestConfig = { ...this.axiosConfig
    };
    //axios.defaults.headers.common = { 'Authorization': 'Bearer ' + this.token }
    var result2 = await axios.get(url, config);
    console.log(result2.data); // -----------------> data coming here
    return result2.data; //------------> not able to return the data from here
    //return axios.get<string>(url, config);   //-------------> tried this way but still not coming
  })
}
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

In your second and third functions, you're returning those axios calls inside an array map. The outer function is not returning anything.

If you add a return before each .map() call, then the functions will return an array of your expected results.

async getfame() {
  var res = await this.getdata()
  return res.map(async(item: any) => {
    /* ... */
    return result1.data; 
  })
}
async getfix() {
  var res1 = await this.getdata()
  return res1.map(async(item: any) => {
    /* ... */
    return result2.data;
  })
}
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda