Ich versuche, die Daten verwenden, die ich von einem Axios-Aufruf abrufen. Ich bekomme die richtigen Informationen zurück in der Antwort, aber wenn ich versuche, Antwort zurückzugeben, werde ich in der aufrufenden Funktion undefiniert. Gibt es eine andere Möglichkeit, die response.data an die aufrufende Funktion zurückzugeben?Mit den Daten von Axios Anruf
static getRequest(url) {
require('es6-promise').polyfill();
axios({
method: 'get',
url: url,
responseType:'json',
withCredentials: true
})
.then(response => {
console.log(response.data);
return response.data;
})
.catch(error => {
if (error.response) {
// The request was made and the server responded with a status code
// that falls out of the range of 2xx
console.log('___________ERROR RESPONSE__________');
console.log(error.response.data);
console.log(error.response.status);
console.log(error.response.headers);
} else if (error.request) {
// The request was made but no response was received
// `error.request` is an instance of XMLHttpRequest in the browser and an instance of
// http.ClientRequest in node.js
console.log('_________ERROR REQUEST_______');
console.log(error.request);
} else {
// Something happened in setting up the request that triggered an
Error
console.log('Error', error.message);
}
console.log('_________ERROR CONFIG_________');
console.log(error.config);
});
}
Dies funktioniert, danke. – Totals