Skip to content
Advertisement

VueJs – Conditional statement / filter on v-for results

So now i’m doing this to organise my results by category but if feel like this could be better:

JavaScript

If found this article doing this with a computed property and i feel like this should be the way but can’t get it to work (also because i need a argument for it to work this way i think?):

JavaScript

and then something like this:

JavaScript

But yeah, it says i can’t pass a argument in that for loop like this so that is where i ended for now.

Anyone got an idea how to do this?

Stashes looks like this:

JavaScript

Advertisement

Answer

While using a method in the template might solve this, it’s not a good pattern because it causes the method to run every time the template is rerendered for any reason. Add another level of v-for:

JavaScript

And create an array of categories like:

JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement