Summary of Vue watch monitoring methods

Summary of Vue watch monitoring methods

In vue , watch is used to respond to data changes. There are roughly three ways to use watch .

1. The role of watch in vue is just like its name, which is the role of monitoring

For example, there is an object:

watchData: {
    name: '',
    age: '',
}


2. Monitor the properties of this object

watchData: {
    handler: function() {
        console.log();
    },
    deep: true
}


The monitoring object can be monitored with deep , otherwise the changes of the object cannot be detected

3. Monitor the properties of this object

Method 1:

watch:
 'watchData.name'(newValue, oldValue) {
     console.log(newValue);
 }
}


Method 2:

watch:
    'watchData.name': {
        handler: function() {
            console.log();
        }
    }
},


Why do we need to monitor the properties of an object? If we monitor an object, any data inside the object will cause watch to be re-executed. This may not be what you want, that is, to monitor a certain property change before executing watch , or to monitor any property change inside the object before executing watch , which will also cause a certain loss in performance. Therefore, we use this method of monitoring a single property of the object to deal with it, and wrap the "object.property to be monitored in quotation marks"

4. Monitor the properties of this object

computed: {
    getName() {
        return this.watchData.name 
    }
},
watch:
    getName(newValue, oldValue) {
        console.log(newValue);
    }
},


This method is actually the same as the second one. The difference is that computed is used, and then the getName method is listened to. In fact, the getName method returns name attribute in the watchData object.

This is the end of this article about the summary of vue watch monitoring method. For more relevant vue watch 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:
  • Solve the pitfalls of calling methods in Vue watch
  • Detailed explanation of watch monitoring data changes in vue and each attribute in watch
  • Detailed explanation of the basic usage of VUE watch listener
  • Triggering timing of watch listener in vue (pitfalls of watch and solutions)

<<:  DHCP Configuration Tutorial in CentOS7 Environment

>>:  CSS implements 0.5px lines to solve mobile compatibility issues (recommended)

Recommend

MySQL query optimization using custom variables

Table of contents Optimizing sorting queries Avoi...

Detailed explanation of Mencached cache configuration based on Nginx

Introduction Memcached is a distributed caching s...

Three examples of blur background effects using CSS3

Let’s not start with the introduction and get str...

Detailed explanation of mysql integrity constraints example

This article describes the MySQL integrity constr...

jQuery achieves the shutter effect (using li positioning)

This article shares the specific code of jQuery t...

HTML table tag tutorial (13): internal border style attributes RULES

RULES can be used to control the style of the int...

MySQL/MariaDB Root Password Reset Tutorial

Preface Forgotten passwords are a problem we ofte...

nginx automatically generates configuration files in docker container

When a company builds Docker automated deployment...

How to use CocosCreator object pool

Table of contents Preface: Specific operations St...

MySQL 8.0.18 uses clone plugin to rebuild MGR implementation

Assume that a node in the three-node MGR is abnor...

About the correct way to convert time in js when importing excel

Table of contents 1. Basics 2. Problem Descriptio...

How to install and configure Docker nginx

Download Nginx image in Docker docker pull nginx ...

Share 20 JavaScript one-line codes

Table of contents 1. Get the value of browser coo...

MySQL efficient query left join and group by (plus index)

mysql efficient query MySQL sacrifices group by t...