Answer the question
In order to leave comments, you need to log in
How to display categories in vue store?
Good afternoon. I'm learning vue and I want to make an online store for practice.
There is a json in which there are products and in each product there are fields like name, price, category.
I want only phones to be shown on this page when clicking on the menu item "phones". I understand that you can make a computed which will be array.filter(item=>item.category='phones') and this will return a list of those products that are in this category, but how to make a universal component?
for example catalog.vue in which the category will change dynamically?
and how to make domain/catalog/phones using router where the last item will change depending on the open menu item?
Answer the question
In order to leave comments, you need to log in
You need to understand that passing parameters to computed is bad practice, it's
better to make a method that takes a parameter for filtering and returns already filtered products, which you then pass to the
domen/catalog/phones component, where phones is a dynamic path, you can get it through this.$router.params
and therefore filter it already
https://router.vuejs.org/en/guide/essentials/neste...
here is a great example
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question