1. Several methods used by Watch (1) Monitor changes of data values through Watch (common monitoring) (2) monitor changes of docData data through Watch. When data changes (deep: Watch: {data: ‘changeData’ // The value can be the name of methods}, methods: {changeData(curVal,oldVal){conosle.log(curVal,oldVal)} (1) Watch is used with immediate and handler. If the value is bound for the first time, the listener function is executed only when the value changes. We need the immediate attribute if we need to execute the function when we first bind the value. watch: { docData: { handler(newVal) { this.change_number++ }, immediate: True}} (2) Deep when it is necessary to monitor the changes of an object, the ordinary watch method cannot monitor the changes of the internal properties of the object, so the deep property is needed to monitor the object deeply. Data () {return {docData: {‘doc_id’: 1, ‘tpl_data’: ‘ABC’}}}, watch: {docData: { handler(newVal) { this.change_number++ }, deep: Docdata. doc_id = true}} deep:true; docdata. doc_id = true; Data () {return {docData: {‘doc_id’: 1, ‘tpl_data’: ‘ABC’}}}, watch: data () {return {docData: {‘doc_id’: 1, ‘tpl_data’: ‘ABC’}}} { ‘docData.doc_id’: { handler(newVal, oldVal) { …… }, deep: true}} this only adds a listener to a particular property of the object
Created (){this.getList()}, watch: {inpVal(){this.getList()}}
3. To sum up, the changes of arrays (one-dimensional and multidimensional) do not require depth monitoring, while the changes of objects’ properties in object arrays require deep depth monitoring.