所以我有个问题,我想让这个Axios第二次返回我,它不起作用,我不明白为什么。因此,这第二秒钟返回我未定义的,但我想从那个或任何数据获得ID,有什么建议吗?我查看了一些其他的帖子,他们似乎有相同的写作,但对我来说,只是不起作用,请帮助:)
如果要检查Axios,请在最后编写?q=Grimm (例如)。所以整个页面是:https://api.tvmaze.com/singlesearch/shows?q=Grimm
.get('https://api.tvmaze.com/singlesearch/shows', {
params: {
q: id,
},
})
.then((res) => setOneShow([res.data]))
.then((res) => console.log(res));发布于 2022-01-19 13:14:45
在.then() chain中,第二个then块获取从第一个then块返回的数据。
在您的示例中,要在第二个then块中获取相同的数据,请将代码修改为:
axios.get("https://api.tvmaze.com/singlesearch/shows", {
params: {
q: id
}
})
.then((res) => {
console.log("1", res);
return res;
})
.then((res) => console.log("2", res));
}发布于 2022-01-19 13:18:19
看看这个课程:,。在第一个setOneShow()方法中调用并返回.then(),而不是res。它应该是什么样的:
axios.get('https://api.tvmaze.com/singlesearch/shows', {
params: {
q: id,
},
})
.then((res) => {
setOneShow([res.data]);
return res;
})
.then((res) => {
console.log(res);
});https://stackoverflow.com/questions/70771123
复制相似问题