[Vuejs]-How to filter array of data with by category?

2👍

To get the filtered list from selected, use a computed

computed{
  filtered(){
    if (this.selected === null) return this.services.list
    return this.services.list.filter(s => s.category === this.selected)
  }
}

Then you can use filtered in your template

👤Daniel

1👍

  computed: {
    filtered() {
      if (this.selected === null) return this.services.list
      return this.services.list.filter(obj => obj.category === this.selected)
    }
  }

Leave a comment