vue failure / listener object properties change when the listener objects

info is an object

//第一种
watch: {
   info(newValue,oldValue) {
    console.log(newValue)
  }
 }
//第二种
watch: {
   info: {
    handler(newValue, oldValue) {
      console.log(newValue)
    },
    deep: true
  }
 }

The difference is that: first info only be reassigned to be effective (v-model binding property values info when the listener does not take effect)
will take effect when the second when the info object properties change


Other methods:
1. by calculating properties

computed: {
  info() {
    ....
  }
},

2. For property listens

'info.name'(newValue, oldValue) {
    console.log(newValue)
  }
Published 634 original articles · won praise 579 · Views 350,000 +

Guess you like

Origin blog.csdn.net/qq_33583069/article/details/104073809