Within my application, there is a seller page showcasing products listed by the specific seller. Utilizing asyncData to retrieve all necessary data for this page has been beneficial in terms of SEO.
asyncData ({params, app, error }) {
return app.$axios.$get(`/seller/${params.username}`).then(async sellerRes => {
let [categoriesRes, reviewsRes, productsRes] = await Promise.all([
app.$axios.$get(`/categories`),
app.$axios.$get(`/seller/${params.username}/reviews`),
app.$axios.$get(`/seller/${params.username}/products`)
])
return {
seller: sellerRes.data,
metaTitle: sellerRes.data.name,
categories: categoriesRes.data,
reviewsSummary: reviewsRes.summary,
products: productsRes.data,
}
}).catch(e => {
error({ statusCode: 404, message: 'Seller not found' })
});
},
Although the current approach gets the job done, I have some doubts about its correctness.
Upon navigating to the page, I've noticed that the Nuxt progress bar appears twice, which seems unusual.
I've spent some time searching for examples of handling multiple requests in asyncData, but resources on this seem scarce.
Could it be that making multiple requests within asyncData might not be the recommended practice?