[Vuejs]-Update Firebase query from filter

0👍

At the moment you need to unbind and rebind again:

watch: {
  'activeFilter': {
    deep: true,
    handler: function(newVal, oldVal) {
      this.$unbind('recipes')
      this.$bindAsArray('recipes', database.ref.child('recipes').orderByChild('type/' + newVal).equalTo(true))
    }
  }
}

I think there is a better solution, you bind all data and do filter on UI. You don’t need to unbind and rebind every time filter is changed.

computed: {
  filterRecipies() {
    const data = this.recipes || [
    if (this.activeFilter) {
       return data.filter(dataItem => dataItem.type.pie)
    }
    return data
  }
}

Leave a comment