Reputation: 1931
I have a very simple Laravel /Vue js website, I have a list of product which I would like to filter.
const app = new Vue({
el: '#main-content',
data: {
forfaits: window.forfaits,
},
methods: {
filterData: function (val) {
console.log(val)
this.forfaits = this.forfaits.filter(item => {
return item.internet >=val[0] && item.internet <= val[1] ;
});
return this.forfaits;
}
HTML
<div class="product-item offre" v-for="forfait in forfaits">
.....
.....
.....
In this case it works but the original product array (forfaits) is mutated. How can I filter without mutating the original value?
Upvotes: 1
Views: 839
Reputation: 887453
You want to have two properties:
You don't need any methods; the computed property will automatically update as the filter changes.
Upvotes: 4