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

Example analysis of interval calculation of mysql date and time

This article uses an example to describe the inte...

Hexadecimal color codes (full)

Red and pink, and their hexadecimal codes. #99003...

Detailed explanation of Linux mpstat command usage

1. mpstat command 1.1 Command Format mpstat [ -A ...

Solution to 1449 and 1045 exceptions when connecting to MySQL

Solution to 1449 and 1045 exceptions when connect...

Mysql command line mode access operation mysql database operation

Usage Environment In cmd mode, enter mysql --vers...

How to install redis5.0.3 in docker

1. Pull the official 5.0.3 image [root@localhost ...

WeChat applet implements fixed header and list table components

Table of contents need: Function Points Rendering...

Web Design Teaching or Learning Program

Section Course content Hours 1 Web Design Overvie...

Ubuntu opens port 22

Scenario You need to use the xshell tool to conne...

Detailed explanation of JS browser event model

Table of contents What is an event A Simple Examp...

Sample code for testing technology application based on Docker+Selenium Grid

Introduction to Selenium Grid Although some new f...

How to hide rar files in pictures

You can save this logo locally as a .rar file and...

Solution to the timeout problem when installing docker-compose with PIP

1: Installation command pip install docker-compos...

Docker data management and network communication usage

You can install Docker and perform simple operati...

JavaScript to achieve slow motion animation effect

This article shares the specific code for JavaScr...