current position：Home>Template rendering and data binding principles of vue2 and vue3
Template rendering and data binding principles of vue2 and vue3
2021-08-27 06:40:27 【Glutinous rice Ctrl_ C】
Vue Of template Rendering process
Vue It is recommended to use in most cases template To create your HTML. But templates are templates after all , It's not real dom node . From template to reality dom Nodes also need to go through some steps
- Compile the template into render function
- Mount the instance , According to the root node render Function call , Recursive generation of virtual dom
- adopt diff Algorithm comparison virtual dom, Render to reality dom（ similar react The virtual DOM Rendering process ）
- Inside the component data change , Component and subcomponent references data As props Call again render function , Generate virtual dom, Go back to step 3.
The principle of bidirectional data binding
vue2.xx Use in Object.defineProperty() Method through recursive + Traverse the way to achieve data monitoring
1.vue Two way data binding is through The data was hijacked combination Publish and subscribe mode to achieve , That is, data and view synchronization , Data changes , The view changes , View changes , And the data changes ;
2. The core ： About VUE Two way data binding , Its core is Object.defineProperty() Method ;
3. Introduce to you Object.defineProperty() Method
（1）Object.defineProperty(obj, prop, descriptor) , There are three parameters in this syntax , Respectively obj （ The object whose properties you want to define ） prop （ Properties to define or modify ） descriptor （ Specific ways to change ）
（2） In short , This is how to define a value . When we call, we use the get Method , When we assign a value to this property , It uses the set Method ;
shortcoming ：1. Methods listening to arrays cannot trigger Object.defineProperty Methods set operation ( If you want to listen , You need to rewrite the array method ).
2. You have to traverse every attribute of every object , If objects are deeply nested , You need to use recursive calls .
vue3 Mentioned with Proxy Instead of defineProperty, Compared with defineProperty How to hijack object properties ,Proxy It is an interception before the object operation , Returns a proxy object of an operand to indirectly manipulate the object
author[Glutinous rice Ctrl_ C],Please bring the original link to reprint, thank you.
The sidebar is recommended
- Crazy blessing! Tencent boss's "million JVM learning notes", real topic of Huawei Java interview 2020-2021
- How to implement injection in vuex source code?
- JQuery operation select (value, setting, selected)
- An article disassembles the pyramid architecture behind the gamefi outbreak
- BEM - a front-end CSS naming methodology
- [vue3] encapsulate custom global plug-ins
- Error using swiper plug-in in Vue
- Another ruthless character fell by 40000, which was "more beautiful" than Passat and maiteng, and didn't lose BMW
guess what you like
Huang Lei basks in Zhang Yixing's album, and the relationship between teachers and apprentices is no less than that in the past. Netizens envy Huang Lei
He was cheated by Wang Xiaofei and Li Chengxuan successively. Is an Yixuan a blessed daughter and not a blessed home?
Zhou Shen sang the theme song of the film "summer friends and sunny days" in mainland China. Netizen: endless aftertaste
Pink is Wangyuan online! Back to the peak! The new hairstyle is creamy and sassy
Front end interview daily 3 + 1 - day 858
Spring Webflux tutorial: how to build reactive web applications
[golang] walk into go language lesson 24 TCP high-level operation
August 23, 2021 Daily: less than three years after its establishment, Google dissolved the health department
The female doctor of Southeast University is no less beautiful than the female star. She has been married four times, and her personal experience has been controversial
There are many potential safety hazards in Chinese restaurant. The top of the program recording shed collapses, and the artist will fall down if he is careless
- Anti Mafia storm: He Yun's helpless son, Sun Xing, is destined to be caught by his dry son
- Introduction to flex flexible layout in CSS -- learning notes
- CSS learning notes - Flex layout (Ruan Yifeng tutorial summary)
- Today, let's talk about the arrow function of ES6
- Some thoughts on small program development
- Talk about mobile terminal adaptation
- Unwilling to cooperate with Wang Yibo again, Zhao Liying's fans went on a collective strike and made a public apology in less than a day
- JS function scope, closure, let, const
- Zheng Shuang's 30th birthday is deserted. Chen Jia has been sending blessings for ten years. Is it really just forgetting to make friends?
- Unveil the mystery of ascension
- Asynchronous solution async await
- Analysis and expansion of Vue infinite scroll source code
- Compression webpack plugin first screen loading optimization
- Specific usage of vue3 video play plug-in
- "The story of huiyeji" -- people are always greedy, and fairies should be spotless!
- Installing Vue devtool for chrome and Firefox
- Basic usage of JS object
- Two easy-to-use animation JS that make the page move
- Front end Engineering - scaffold
- Java SQL Server intelligent fixed asset management, back end + front end + mobile end
- Array de duplication problem solution - Nan recognition problem
- New choice for app development: building mobile applications using Vue native
- New gs8 Chengdu auto show announces interior Toyota technology blessing
- Vieira officially terminated his contract and left the team. The national security club sent blessings to him
- Less than 200000 to buy a Ford RV? 2.0T gasoline / diesel power, horizontal bed / longitudinal bed layout can be selected
- How does "heart 4" come to an end? Pinhole was boycotted by the brand, Ma Dong deleted the bad comments, and no one blessed him
- We are fearless in epidemic prevention and control -- pay tribute to the front-line workers of epidemic prevention!
- Front end, netty framework tutorial
- Xiaomi 11 | miui12.5 | android11 solves the problem that the httpcanary certificate cannot be installed
- The wireless charging of SAIC Roewe rx5 plus is so easy to use!
-  typescript
- CSS transform Complete Guide (Second Edition) flight.archives 007
- Ajax foundation - HTTP foundation of interview essential knowledge
- Cloud lesson | explain in detail how Huawei cloud exclusive load balancing charges
- [JS] 10. Closure application (loop processing)
- Left hand IRR, right hand NPV, master the password of getting rich