Search code examples
vue.jsreduxvuex

How to apply a filter computed property to a computed property inside Vuex's mapState?


I have a list of shipments correctly being rendered into the DOM. Such an array of shipments is defined like this inside the component:

computed: mapState([
    'shipments'
])

Now I want to filter the array based on certain criteria. I had this perfectly implemented before inserting Vuex into the app. The computed property that used to do this before, looks like this:

filteredShipments() {
   // Some processing

   let filtered = arr.filter(shipment => shipment.criteria);
   return filtered;
}

What's the correct syntax to filter shipmentsbased on filteredShipments()?


Solution

  • I got it. This is solved with the spread operator:

    computed: {
       ...mapState([
          'shipments'
       ]),
       filteredShipments() { 
           // logic
       }
    }