vue2.xdata(){ return { num:10 } }, watch:{ num:{ /* * newValue: current value * oldValue: modify the value of the last moment */ handler(newValue,oldValue){ // doSomething }, /* * deep: Boolean: Deep monitoring * true: monitor heap changes * false: only monitor stack changes (default) */ deep:true/false, /* * immediate:Boolean: Whether to execute the handler function when it is first defined* true: execute the handler function when it is first defined* false: execute the handler function after modification*/ immediate:true/false } } vue3.xWatch is used to monitor responsive data Basic Use const num = ref(0) 1. Import import {watch} from 'vue' 2. Use `const return value = watch(value to be monitored, (newVal,oldVal)=>{ }, {deep,immediate,flush})` Return value: You can turn off monitoring: return value() Parameter 1: The value to be monitored Basic data types (Number, String, Boolean, null, undefined): () => Basic data type value Complex data types (Array, Object, Function): Directly write / () => Basic data type value Parameter 2: Analogy to the handler function in Vue2 Parameter 3: {} object, the object can have a configuration item: deep, immediate, flush, The meanings of deep and immediate have been described above. Here we mainly explain the values of flush: `flush:post/sync/pre pre (default value): before rendering, the value is changed and not rendered to the DOM post: After rendering, the value changes and is also rendered to the DOM sync: Render once per change, each time before rendering` Note:
The above is the detailed content of how to use the watch listener in Vue2 and Vue3. For more information on the use of watch listeners, please pay attention to other related articles on 123WORDPRESS.COM! You may also be interested in:
|
<<: MySql index improves query speed common methods code examples
>>: Tomcat CentOS installation process diagram
Operating system: Ubuntu 17.04 64-bit MySQL versi...
Preface The author has always felt that it would ...
MySQL 8.0.22 installation and configuration metho...
This article mainly introduces the analysis of th...
//MySQL statement SELECT * FROM `MyTable` WHERE `...
1. To build a PPTP VPN, you need to open port 172...
The question is referenced from: https://www.zhih...
Mysql is a popular and easy-to-use database softw...
Today we will introduce how to publish the local ...
I won’t waste any more time talking nonsense, let...
To connect Node-red to the database (mysql), you ...
Product designers face complex and large manufactu...
Add an input file HTML control to the web page: &...
We deal with Linux servers every day, especially ...
The configuration method of MySQL 5.5.56 free ins...