[Vuejs]-VueJS: Updating component collection data from its child

0👍

computed properties have the ability to create and return a filtered list.

this example uses lodash

data: {
  items: [
    {name: 'thing 1', value: 1000},
    {name: 'thing 2', value: 50},
    {name: 'thing 3', value: 250},
    {name: 'thing 4', value: 342},
  ],
},
computed: {
  orderedItems() {
    let items = []
    return _.orderBy(this.items, 'value', 'desc');
  },
}

to update pass the index from orderedItems array into the “this.items” array.

0👍

I found some solution that works – instead of passing all params of todo-item into component, pass whole object:

    <todo-item
      v-for="item in selectedItems"
      :item="item"
    />

Then object in parent collection is updated automatically.

Is that a good way of doing that in Vue?

Leave a comment