将控制台日志放在axios的何处获取请求?
我正在尝试创建一个功能,以从LinkedIn上获取我的个人资料。为了进行调试,我需要查看在其之前或之前已映射了哪些数据。但不确定将控制台日志放在何处以查看其接收的数据。任何帮助都非常感激:)
// Grabs profile data from the json url
private getProfiles() {
let config = {
headers: {'Authorization':'Bearer AQVVEqG......'}
}
axios
.get("/" + "", config)
.then(response =>
response.data.map(profile => ({
name: `${ profile.localizedLastName }`,
}))
)
.then(profiles => {
this.setState({
profiles,
isLoading: false
});
})
// We can still use the `.catch()` method since axios is promise-based
.catch(error => this.setState({ error, isLoading: false }));
}
回答如下:只需将其放在回调函数中。
.then(response => {
console.log(response);
response.data.map(profile => ({
name: `${ profile.localizedLastName }`,
}))
})
.then(profiles => {
console.log(profiles);
this.setState({
profiles,
isLoading: false
});
})
将控制台日志放在axios的何处获取请求?
我正在尝试创建一个功能,以从LinkedIn上获取我的个人资料。为了进行调试,我需要查看在其之前或之前已映射了哪些数据。但不确定将控制台日志放在何处以查看其接收的数据。任何帮助都非常感激:)
// Grabs profile data from the json url
private getProfiles() {
let config = {
headers: {'Authorization':'Bearer AQVVEqG......'}
}
axios
.get("/" + "", config)
.then(response =>
response.data.map(profile => ({
name: `${ profile.localizedLastName }`,
}))
)
.then(profiles => {
this.setState({
profiles,
isLoading: false
});
})
// We can still use the `.catch()` method since axios is promise-based
.catch(error => this.setState({ error, isLoading: false }));
}
回答如下:只需将其放在回调函数中。
.then(response => {
console.log(response);
response.data.map(profile => ({
name: `${ profile.localizedLastName }`,
}))
})
.then(profiles => {
console.log(profiles);
this.setState({
profiles,
isLoading: false
});
})