1

我正在尝试获取所有电影,但 API 仅返回前 10 部电影。任何帮助,将不胜感激。

async getResults(page = 1) {
    const apiKey = '#######';
    const proxy = 'http://cors-anywhere.herokuapp.com/';
    try {

        while (page <= 5) {
            const res = await axios(`${proxy}http://www.omdbapi.com/? apikey=${apiKey}&s=${this.query}&type=movie&page=${page}`);
            this.result = res.data;
            this.page = page;
            page++;
        }

    } catch (error) {
        console.log(error);
    }

} 
4

1 回答 1

1

OMDB API 具有分页功能,这意味着它将在每个请求中返回一定数量的电影响应数据。在这种情况下,每个请求返回 10 部电影。page=2如果要获取第二页的数据,则必须传递查询参数,因为 page 不是必需的查询参数,默认为 1。

查看官方OMDB 文档以获取更多信息

于 2020-10-10T13:29:12.093 回答