Javascript 如何在Vanilla Javascriot中的Unsplash Api中使用分页

Javascript 如何在Vanilla Javascriot中的Unsplash Api中使用分页,javascript,arrays,api,async-await,dom-events,Javascript,Arrays,Api,Async Await,Dom Events,我正试图使一个网站与无限滚动的狗的照片(unsplashAPI)功能。但是,当我在scroll事件上调用getphotos()函数时,它只提供第一页上的图像 我试图通过生成3个不同的getphotos()函数并传递不同的APIRL(属性页码已更改)来修复此问题。这确实有效,但我认为这不是最好的方法。我看了一下文档,似乎什么都不管用。我想在滚动事件中调用getphotos()函数,每次它都应该返回来自不同页面的图像 const apiUrl = `https://api.unsplash.com/

我正试图使一个网站与无限滚动的狗的照片(unsplashAPI)功能。但是,当我在scroll事件上调用getphotos()函数时,它只提供第一页上的图像

我试图通过生成3个不同的getphotos()函数并传递不同的APIRL(属性页码已更改)来修复此问题。这确实有效,但我认为这不是最好的方法。我看了一下文档,似乎什么都不管用。我想在滚动事件中调用getphotos()函数,每次它都应该返回来自不同页面的图像

const apiUrl = `https://api.unsplash.com/search/photos/?page=1&query=dogs&client_id=${apiKey}&per_page=${per_page}&order_by=relevant;` 

const apiUrl2 = `https://api.unsplash.com/search/photos/?page=2&query=dogs&client_id=${apiKey}&per_page=${per_page}&order_by=relevant;`

const apiUrl3 = `https://api.unsplash.com/search/photos/?page=3&query=dogs&client_id=${apiKey}&per_page=${per_page}&order_by=relevant;` 



 async function getPhotos(){
    try{
        const response = await fetch(apiUrl);
        photosArray = await response.json();
        console.log(photosArray);
        displayPhotos();
    }catch(error){
        console.log(error);
    }
}

async function getPhotos2(){
    try{
        const response = await fetch(apiUrl2);
        photosArray = await response.json();
        displayPhotos();
        getPhotos3();
    }catch(error){
        console.log(error);
    }
}

async function getPhotos3(){
    try{
        const response = await fetch(apiUrl3);
        photosArray = await response.json();
        displayPhotos();
    }catch(error){
        console.log(error);
    }
}