jeudi 28 septembre 2017

Vue js 2 : How to filter array without mutation?

I have a very simple Laravel /Vue js website, i have a list of product wich 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 ?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire