react中omdb api上每页30部电影

4si2a6ki  于 2021-09-13  发布在  Java
关注(0)|答案(1)|浏览(339)

我正在尝试合并页面以将项目增加到20、30,因为omdb每页只有10个。我需要从第1、2和3页获取所有的“imdbid”。
api显示了以下结果:

"Search": [
{
"Title": "Home",
"Year": "2009",
"imdbID": "tt1014762",
"Type": "movie",
"Poster": "https://m.media-amazon.com/images/M/MV5BODY2ZTNmMjEtMWEyNC00YjZlLWEyMGEtZWFiNGMwYmQ5NWViXkEyXkFqcGdeQXVyMTAwMzM3NDI3._V1_SX300.jpg"
},
]

//my code

async function getRequest(){
const pageOne = await axios
.get('http://www.omdbapi.com/?s=${searchText}&apikey=ef773fae&page=1')
.then(res=>res.data)
.catch(error=>console.log(error));

const pageTwo = await axios
.get('http://www.omdbapi.com/?s=${searchText}&apikey=ef773fae&page=2')
.then(res=>res.data)
.catch(error=>console.log(error));

const pageThree = await axios
.get('http://www.omdbapi.com/?s=${searchText}&apikey=ef773fae&page=3')
.then(res=>res.data)
.catch(error=>console.log(error));

const sumPage= {pageOne, pageTwo, pageThree};

//not sure how to write this line of code to get all the imdbID
return sumPage.map(movie => movie.imdbID);
}

getRequest();

7ivaypg9

7ivaypg91#

把它们分散成一个阵列怎么样

return {"Search":[...pageOne.Search, ...pageTwo.Search, ...pageThree.Search]};

相关问题