简体   繁体   中英

I tried to use the .map function but it didn't work on my code

async function getCategoryIds ()
{
    let response = axios.get( `${BASE_API_URL}categories?count=100` );
    let catIds = response.data.map( c => c.id );
    return _.samplesize( catIds, NUM_CATEGORIES )  
};

This is my code I tried to change the data in [] but it still don't work

The main issue here is you have not used await in your code. adding await like the following should solve your problem -

let response = await axios.get( `${BASE_API_URL}categories?count=100` );

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM