[Vuejs]-Vuejs: Update computed property when nested data changes

4👍

Nested object properties aren’t automatically re-evaluated. You can watch for its changes with watch. Here is the documentation for more info. The relevant part you need is:

var vm = new Vue({
  el: '#app',
  computed: {
    foo() { return this.item.foo; }
  },
  watch: {
    foo() { console.log('Foo Changed!'); }
  },
  data: {
    item: { foo: 'foo' }
  }
})

Leave a comment