0
votes

I have computed property which returns the data from getters (vuex) which is again being used in template to show data.

computed: {
    returnlist() {
    
      return this.$store.getters[LIST]
    },
}

Now I have filters which has needs to do search within available result from computed property.

I am trying

method :{
  search() {
    this.returnlist.filter(el=>el.name==="test")

}

However this does not filter and if I console I am getting same array provided it matches with given name property.

1
el.name="test" Is this what you need exactly. I think you should be doing el.name=="test" instead.VarunDevPro
it was typo, I have already === there, but no luck, my question is that can we search in data return by computed propertyvuejsdev

1 Answers

1
votes

Your search method is not returning anything. Depending on how you want to use it, you could either have your search function return the filtered array:

methods: {
  search() {
    return this.returnlist.filter(el => el.name === "TEST");
  }
}

or you could have an object holding filter values in your component's data and change the filter values to adjust the returned filtered array:

data: {
  filters: {
    name: 'Jack',
    minAge: 32
    maxAge: 40,
  },
},

computed: {

  filteredArray() {
    return this.$store.getters[LIST].filter(el => {
      return el.name === this.filters.name &&
            (el.age >= this.filters.minAge &&
             el.age <= this.filters.maxAge);
    });
  }
},