Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use Vue's watch listener

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

The editor will share with you how to use Vue's watch listener. I hope you will get something after reading this article. Let's discuss it together.

Listener watch

The function name is the name of the element to listen for

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

Listeners in the format of the

It cannot be triggered automatically when you first enter the page, but only when a change is heard.

If you are listening on an object, it will not be heard when the properties of the object change.

Listeners in object format

The immediate option allows the listener to trigger automatically

Use the deep option to make the listener listen deeply to changes in attributes in the object

This is the data object in the Vue instance:

Set up the listener:

Here are method-formatted listeners and object-formatted listeners:

Method-formatted listener triggers listening when the content in the input changes, listens for the content in the input (the content is bound to the tem), and adds it to the already if the content in the current input is not in the already array, otherwise the pop-up prompt box already exists

Object-formatted listeners implement that as soon as the page is loaded, it triggers listening for changes in the name property of the foo object.

After reading this article, I believe you have a certain understanding of "how to use Vue's watch listener". If you want to know more about it, you are welcome to follow the industry information channel. Thank you for reading!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report