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
When shutting down the MySQL server, various prob...
Designers need to understand psychology reading n...
1. From father to son Define the props field in t...
Stop MySQL Service Windows can right-click My Com...
This article shares the specific code of js to re...
Preface Today, after synchronizing the order data...
Copy code The code is as follows: <!--[if !IE]...
Table of contents 1 A brief introduction to syste...
Table of contents 0. What is Module 1.Module load...
First, let me introduce the meaning of some field...
1. What is the use of slow query? It can record a...
Table of contents Preface Type Inference Truth va...
Table of contents 1. MySQL replication related co...
Most browsers will cache input values by defaul...
A few days ago, the library said that the server ...