【发布时间】:2022-01-21 13:49:18
【问题描述】:
多个axios返回无法返回值但在控制台中它来了 第一个函数能够返回数据> 第二和第三不能做>
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
})
}
【问题讨论】:
标签: javascript angular async-await axios