I try to filter an object of array in Vue.js. have products collection in this vue component. I would like to filter this collection with select buttons. These products are food products and as default I would like to show all products but if I select the lactosefree button the I would like to show only products are lactosefree. In my database these options true or false. so for example if I have a cheese that lactose free then in the database I have a field lactosefree with value true.
I have tried to filter the array with computed property but I don't really know how to do it.
<div class="col-12 justify-content-between row filterbtn">
<label class="btn btn-primary">
<input v-model="selected" value="gluteinfree" type="checkbox" class="check2">GLUTEIN FREE
</label>
<label class="btn btn-primary">
<input v-model="selected" value="lactosefree" type="checkbox" class="check2">LAKTOZ FREE
</label>
</div>
<script>
export default{
data(){
return{
products: [
{ "id": 1, "productName": "Majomkenyérfa kivonat", "gluteinfree": true, "lactosefree": false, },
{ "id": 2, "productName": "Kókuszolaj", "gluteinfree": false, "lactosefree": true,},
{ "id": 3, "productName": "C-vitamin 80mg", "gluteinfree": true, "lactosefree": true, },
],
selected: [],
}
},
computed: {
//
},
}
</script>
As default I would like to show all the products. but when i click the gluteinfree select button I would like to show only the First and the last products where the gluteinfree is true.