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
The implementation of expanding and collapsing li...
Problem Description When filter attribute is used...
Today, I am sharing the valuable experience of a ...
Often, after a web design is completed, the desig...
This article shares the specific code for impleme...
1. Download jdk download address我下載的是jdk-8u221-li...
Simulation tables and data scripts Copy the follo...
When using MySql's window function to collect...
This article mainly introduces CSS circular hollo...
This article will introduce how to use explain to...
Table of contents introduction scroll Element.scr...
Table of contents 1. unzip command 1.1 Syntax 1.2...
Many people say that IE6 does not support PNG tra...
Mysql installation, configuration, and optimizati...
1. Refer to the official website to install docke...