I
I
igor_solweb2020-09-01 12:53:08
JavaScript
igor_solweb, 2020-09-01 12:53:08

How to use filter + sort at the same time in Vue?

5f4e18f0c6a8b421963299.jpeg
There are two filters for selecting from products by them, how best and more correctly to implement sorting and filtering together?
That is, when choosing a Category, the filter should also be taken into account in the opposite direction, too, so far it turned out to do only a separate sorting by price and name, I did it through .sort((a, b) => a.price < b.price ? 1 : -1 );
When choosing a category, I use .filter(), but it filters inside the array, but does not output, that is, when sorting is applied, everything is displayed at once (products in the component are redrawn), but not when filtering.
Tell me where to look, maybe there is an example, thanks in advance

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0xD34F, 2020-09-01
@igor_solweb

Make a computed property where all the data transformations you need will be performed. For example .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question