current position:Home>Watch data monitoring in Vue and detailed explanation of various attributes in watch
Watch data monitoring in Vue and detailed explanation of various attributes in watch
2022-04-29 07:26:03【MFG_ six hundred and sixty-six】
Catalog
vue in watch Main monitor data Medium is
Array
,object
OfValue change
1、watch Several methods used
(1) adopt watch monitor data Data change , When the data changes , The current value will be printed
watch: {
data(val, newval) {
console.log(val)
console.log(newval)
}
}
(2) adopt watch monitor docData Data change , When the data changes ,this.change_number++( Use deep listening )
watch: {
data: 'changeData' // The value can be methods Method name of
},
methods: {
changeData(curVal,oldVal){
conosle.log(curVal,oldVal)
}
}
2、 Detailed explanation watch Medium immediate、handler and deep attribute
(1)immediate and handler
Use this way watch There is a characteristic when , When the value is bound for the first time , No listening function will be executed , Only when the value changes will it execute . If we need to first
The function is also executed when binding values , Then need
be used immediate
attribute .
for example :
watch: {
docData: {
handler(newVal) {
this.change_number++
},
immediate: true
}
}
(2)deep
When you need to Listen for changes to an object
when , ordinary watch Method cannot listen for changes in the internal properties of an object , At this point, we need deep attribute
Deep listening to objects .
for example :
data() {
return {
docData: {
'doc_id': 1,
'tpl_data': 'abc'
}
}
},
watch: {
docData: {
handler(newVal) {
this.change_number++
},
deep: true
}
}
Set up deep:true You can listen docData.doc_id The change of , It will be given at this time. docData Add this listener to all properties of the , When There are many object attributes
when , Every property value change is performed handler. If You only need to listen for one attribute value in the object
, You can do the following optimization : Listen for object properties in the form of strings :
for example :
data() {
return {
docData: {
'doc_id': 1,
'tpl_data': 'abc'
}
}
},
watch: {
'docData.doc_id': {
handler(newVal, oldVal) {
......
},
deep: true
}
}
The listener will only add such attributes to a specific object
3、 summary
Array
( A one-dimensional 、 Multidimensional ) The change of Unwanted
Through deep monitoring , object
If the properties of the objects in the array change need deep
Deep monitoring .
If you feel the article is good, remember to pay attention and collect , If there is something wrong, please correct it , If you need to reprint , Please indicate the source , Thank you very much !!!
copyright notice
author[MFG_ six hundred and sixty-six],Please bring the original link to reprint, thank you.
https://en.qdmana.com/2022/119/202204290458555866.html
The sidebar is recommended
- How to realize Ethernet wireless communication between 200smartplc?
- Still working on nginx configuration? Try this visual configuration tool. It's really powerful!
- Simple sorting of JavaScript deep copy and shallow copy
- React realizes the communication of brother components by means of message subscription and publication
- React limits props
- Java lesson 30
- Java lesson 29 136 The number 1189 appears only once Maximum number of balloons
- Simple sorting of JavaScript deep copy and shallow copy
- "Geely" new SUV is equipped with frameless doors, and the interior is more beautiful than Mercedes Benz. Can 19 universal accept it?
- Configuration of using less in react project
guess what you like
Expression used in react render
React configuration agent
JQuery sends a post request (a method of connecting PHP variables to strings)
Solve the problem that Django cannot access the local server( http://127.0.0.1:8000/ )Or the problem that the command line execution (Python 3 manage.py runserver 0.0.0.0:8000) does not respond
Summary of the writing method of react router V6
Bipeng ditch, punch in and net red, open-air boundless swimming pool, Ramada hot spring, encounter the beauty of the four seasons
JavaScript gets and modifies elements. What's wrong with not extracting the classlist attribute
Mixed mixin of Vue
Vue + element implements table filtering
Vue router2. 0
Random recommended
- Which one charges less for opening a securities account and how to open the account
- Spring MVC notes 02 domain object sharing data, view, restful, httpmessageconverter, file upload and download
- Httpclient setting timeout
- Command line / Python uses pdf2htmlex to convert PDF to HTML
- [front end three swordsmen III] analysis of JavaScript scalpel Part II
- How to choose the front-end learning path
- Finite element parametric element, calculation, theoretical problems
- Handwritten CSS modules to understand its principle
- Front end browser debugging tips
- Performance problem analysis guide for enterprise JavaScript applications running in production systems
- CSS aspect-ratio All In One
- Actual combat of vue3 project --- Zhihu daily --- details page
- Actual combat of vue3 project --- Zhihu daily --- home page function
- Great Wall Motors is falling endlessly! The boss has lost 150 billion yuan in half a year, and the performance of the new energy sector has improved
- Nginx tips batch shutdown process
- Openresty introduces nginx_ upstream_ check_ Module module
- Nginx multiple servers_ How does name match
- Why does the front end still prompt cannot post, and the error reported by the back end still prompt null pointer?
- HTML Li set margin: 50%, but the width of the outermost div is the standard
- Are there any specific steps to create a prototype, such as JavaScript?
- How does HTML5 display the value obtained from the database in the specified area
- Problems related to nginx rewriting interface
- What happens when you open a CSS file in eclipse without responding
- React download local template can be downloaded locally, but the deployment online download is blank
- @Babel / traverse official example running error: typeerror: traverse is not a function
- The click event of jQuery has no effect
- How to learn from non professional background?
- Usage of API documented as @since 1.8+ less... (Ctrl+F1) Inspection info: This inspection finds all
- Configuration Vue of webpack
- Introduction to nginx (learning notes)
- Is the financial management class of qiniu school true? Can you learn how to manage money in free lessons
- How does Java randomly get elements from a list
- Use of Vue on in Vue
- Use of Vue router
- Vue basic syntax
- Use of webpack
- Vue diff algorithm
- CSS -- Text gradient from top to bottom
- Routing: Vue router
- Leetcode 658. Find K closest elements