An article teaches you how to use Vue's watch listener

An article teaches you how to use Vue's watch listener

Listener watch

  • The function name is the name of the element to listen to.
  • The first parameter passed in is the new value newval after the change, and the second is the old value oldval before the change

Format

Listener in method format

  • It cannot be triggered automatically when entering the page. It will only be triggered when changes are detected.
  • If you listen to an object, you will not hear when the object's properties change.

Object format listener

  • The immediate option allows the listener to be triggered automatically
  • The deep option allows the listener to listen deeply to changes in the properties of the object.

This is the data object in the Vue instance:

insert image description here

Set up the listener:

The following are listeners in method format and listeners in object format:

The listener in method format is implemented by triggering the listener when the content in the input changes, listening to the content in the input (the content is bound to the term). If the content in the current input is not in the already array, it is added to the already array, otherwise a prompt box pops up to indicate that the name already exists.

The object-format listener is implemented by triggering the listener immediately once the page is loaded, listening for changes in the name attribute of the foo object.

insert image description here

Summarize

This article ends here. I hope it can be helpful to you. I also hope you can pay more attention to more content on 123WORDPRESS.COM!

You may also be interested in:
  • Detailed explanation of the watch listener example in vue3.0
  • How to use watch listeners in Vue2 and Vue3
  • Solve the problem of undefined when calling this in vue listener watch
  • Vue 2.0 listener watch attribute code detailed explanation
  • Advanced examples of watch usage in Vue.js

<<:  Detailed explanation of the difference between flex and inline-flex in CSS

>>:  HTML head structure

Recommend

Detailed explanation of MySQL basic operations (Part 2)

Preface This article contains 1. Several major co...

Analysis of the reasons why MySQL field definitions should not use null

Why is NULL so often used? (1) Java's null Nu...

About CSS floating and canceling floating

Definition of Float Sets the element out of the n...

Invalid solution when defining multiple class attributes in HTML

In the process of writing HTML, we often define mu...

Implementation of dynamic particle background plugin for Vue login page

Table of contents The dynamic particle effects ar...

Detailed steps to download Tomcat and put it on Linux

If you have just come into contact with Linux, th...

Common operation commands of MySQL in Linux system

Serve: # chkconfig --list List all system service...

Solve the error "Can't locate ExtUtils/MakeMaker.pm in @INC"

When installing mha4mysql, the steps are roughly:...

Specific use of CSS content attribute

The content attribute is generally used in the ::...

Native js to achieve accordion effect

In actual web page development, accordions also a...

Why can't I see the access interface for Docker Tomcat?

Question: Is the origin server unable to find a r...

Pagination Examples and Good Practices

<br />Structure and hierarchy reduce complex...

docker-maven-plugin packages the image and uploads it to a private warehouse

Table of contents 1. Introduction to docker-maven...