I want to render products by categories. So far I can render products with v-for, but I want similar products to render according to category.
I am fetching data from Django via DRF while using webpack and Vuex. I know I can't use v-if and v-for, so please tell me how can I render products while getting categories from filteredCategorys. I'm a new learner so sorry if I'm not clear about the question.
<base-card-food>
<div v-if="isLoading">
<base-spinner></base-spinner>
</div>
<ul v-else-if="hasFoods">
<food-item
v-for="food in filteredFoods"
:key="food.id"
:id="food.id"
:name="food.name"
:category="food.category"
:description="food.description"
:base_price="food.base_price"
:photo="food.photo"
></food-item>
<ul>
<li v-for="cat in filteredCategorys" :key="cat.id">
{{ cat.id }}
{{ cat.name }}
</li>
</ul>
</ul>
<h3 v-else>No foods found.</h3>
</base-card-food>
computed: {
filteredCategorys() {
const categorys = this.$store.getters['categorys/categorys'];
return categorys;
},
filteredFoods() {
const foods = this.$store.getters['foods/foods'];
return foods;
}
}