0
Q:

vue watch deep property

watch: {
    colors: {
        handler(newValue){
            console.log('colors changed', newValue)
        }, deep: true
    }
}
4
export default {
  name: 'ColorChange',
  props: {
    colors: {
      type: Array,
      required: true,
    },
  },
  watch: {
    colors: {
      // This will let Vue know to look inside the array
      deep: true,

      // We have to move our method to a handler field
      handler(value) {
        console.log('The list of colors has changed!', value);
      }
    }
  }
}
4
...
watch:{
    'item.someOtherProp'(newVal){
        //to work with changes in "myArray"
    },
    'item.prop'(newVal){
        //to work with changes in prop
    }
}
2
watch: {
  item: {
     handler(val){
       // do stuff
     },
     deep: true
  }
}
0

New to Communities?

Join the community