Monitoring method in Vue
Notice Name: You should give the same name to the attribute you want to monitor. 1. FunctionUsed to monitor data changes in the vue instance and modify state changes at any time 2. Trigger conditionsWhen the property you monitor changes, the corresponding monitoring method will be called automatically 3. Usage scenariosUsed for asynchronous processing and relatively expensive operations 4. Exampleswatch:{ name(newvalue,oldvalue){ //Calculated properties can accept two parameters, the first parameter is the new property value, the second parameter is the old property value // this.age // console.log('name property has changed') console.log(newvalue,oldvalue) } 5. When monitoring an object<script> export default { data() { return { obj: { name: "Zhang San", age: 20, children: [ { name: "Li Si", age: 27 }, { name: "Wang Wu", age: 23 } ] } }; }, watch: obj: { handler: function(newVal, oldVal) { console.log("newVal:", newVal); console.log("oldVal:", oldVal); }, deep: true, immediate: true }, "obj.name": function(newVal, oldVal) { console.log("newVal obj.name:", newVal); console.log("oldVal obj.name:", oldVal); } }, }; </script>
immediate attribute: Boolean value
It turns on deep listening, that is, listeners are added to all attributes, and the handler function is executed if one of them changes. This is the end of this article about the detailed case of Vue's monitoring method. For more relevant Vue's monitoring method content, please search 123WORDPRESS.COM's previous articles or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: MySQL 5.7 installation and configuration tutorial under CentOS7 64 bit
>>: CentOS 6 uses Docker to deploy redis master-slave database operation example
summary During the interview, when discussing abo...
Preface Samba is a free software that implements ...
1. How to use the link: Copy code The code is as f...
Preface Previously, I talked about the problem of...
Table of contents 01 ReplicaSet Architecture 02 I...
Previously, the images we used were all pulled fr...
Table of contents 1. Introduction to basic concep...
Table of contents Kill instruction execution prin...
Yesterday I installed CentOS7 under VMware. I wan...
HTML5 adds a native placeholder attribute for inp...
Analyze the execution process. Move the mouse int...
Detailed explanation of mysql exists and not exis...
To connect Node-red to the database (mysql), you ...
In the project (nodejs), multiple data need to be...
Table of contents Introduction to NIS Network env...