1π
You can use Promise.all() and a map() instead of a forEach.
const allCategory = [];
if (Array.isArray(categoryTreeItems.value)) {
const categoryFilter = [3338, 4775, 3411, 3995, 3949, 2934, 3071, 3462, 3629, 5239];
await Promise.all(categoryFilter.map(async (cate) => {
const {category: categoryData, search: searchCategoriesData} = useCategory('category-data-search');
await searchCategoriesData({id: cate});
if (categoryData.value.image_url.length > 0) {
allCategory.push(categoryData.value);
}
}));
}
π€Spoke44
- [Vuejs]-VueJs Axios β Request headers
- [Vuejs]-Calling a child component's method from the parent in Vue composition API?
0π
Reading how an id:βinβ works,it seems to me you have to collect the ids in an array & join them with β,β.The following should do the trick.
const promises = [];
let ids =[]; // id's to be collected
let result // result
if (Array.isArray(categoryTreeItems.value)) {
const categoryFilter = [3338, 4775, 3411, 3995, 3949, 2934, 3071, 3462, 3629, 5239];
categoryFilter.forEach((cate) => {
const {category: categoryData, search: searchCategoriesData} = useCategory('category-data-search');
ids.push(cate)
if (categoryData.value.image_url.length > 0) {
allCategory.push(categoryData.value);
}
});
results = await searchCategoriesData({id: `in=${ids.join(',')}`})
}
π€anuragb26
- [Vuejs]-How to display a vertical bar chart with multiple datasets that coming from an FastAPI endpoint in Vue.js?
- [Vuejs]-How use fadeIn or similar on v-show
Source:stackexchange.com