How to load more than 100 stories with the JS client in NuxtJS?
- FAQ
- How to load more than 100 stories with the JS client in NuxtJS?
1. According to specific amount of pages
let per_page = 100
let requests = []
let totalPages = 10 // 10 pages
for(let i = 1; i <= totalPages; i++) {
requests.push(app.$storyapi.get('cdn/stories/', {
starts_with: 'posts/',
per_page: per_page,
page: i
}))
}
let responses = await Promise.all(requests)
2. All with head request
let per_page = 100
let requests = []
let initial = await app.$storyapi.client.head('cdn/stories/', { params: { per_page: 1, page: 1, token: app.$storyapi.accessToken } })
// access total header -> Total amount of Stories
// and calculate Total amount of pages
let totalPages = Math.ceil(initial.headers.total / per_page)
for(let i = 1; i <= totalPages; i++) {
requests.push(app.$storyapi.get('cdn/stories/', {
starts_with: 'posts/',
per_page: per_page,
page: i
}))
}
let responses = await Promise.all(requests)