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
<br />In general guestbooks, forums and othe...
1. Javascript returns to the previous page history...
Introduction to Docker Docker is an open source c...
Preface When introducing defineProperty before, I...
Table of contents HTTP hijacking, DNS hijacking a...
In enterprises, database high availability has al...
This article uses examples to describe advanced u...
vue scaffolding -> vue.cli Quickly create a la...
Many friends have asked in forums and message are...
I struggled with a problem for a long time and re...
Preface Let me share with you how to make a searc...
Table of contents 1. How to represent the current...
background The interface domain name is not hard-...
Sometimes we save a lot of duplicate data in the ...
I have been using MySQL recently. The article mys...