当前位置:网站首页>The role of diff and key
The role of diff and key
2022-07-30 01:27:00 【Big chicken thighs are the best】
The function of the key is mainly to update the virtual DOM efficiently. When comparing the old and new virtual DOM, you can accurately judge whether two nodes are the same through the key, so as to avoid frequent updating of different elements and make the entire comparisonThe process is more efficient, reducing the amount of DOM operations and improving performance;
diff algorithm
- Comparisons will only be performed at the same level, not across levels
- During the diff comparison, the loop compares from both sides to the middle
When the page data changes, vue will generate a new vnode and extract the old vnode, add the head and tail pointers to both sides respectively, the new vnode is newStart and newEnd point to its head and tail nodes respectively, and the old vnode is oldStartand oldEnd also point to his head and tail nodes respectively
When comparing, the oldStart<—>newStart, oldStart<—>newEnd, oldEnd<—>newStart, oldEnd<—>newEnd will be compared first; if the two are the same, the old node will be correspondingThe real DOM is moved to the position of the new node, and both parties move the matching pointer to the middle; if the above four comparisons fail, if there is no key currently, the real DOM will directly add a new node at the newStart position, newStartMove backward; if there is a pointer, go to the mapping table of the old vnode to find it. If not, the real dom will directly add a new node at the newStart position. If there is, it will compare whether the contents of the two are different. If there is no difference, then the real dom corresponding to the old node will be moved to the position of the new node;
When oldStart > oldEnd or newStart > newEnd, the comparison is completed;
After the comparison is completed, if newStart <= newEnd, then the node between newStart and newEnd is a new node.Then the real dom will add corresponding nodes between the current newStart and newEnd; if it is newStart> newEnd, it means that the nodes between the two are deleted, and the real dom deletes these nodes;
边栏推荐
- Recommendation system: collection of user "behavioral data" [use Kafka and Cassandra to process data] [if it overlaps with business data, it also needs to be collected independently]
- 基于SSM实现个性化健康饮食推荐系统
- LeetCode/Scala - without the firstborn of the string of characters, the longest text string back
- 2022-07-29:一共有n个人,从左到右排列,依次编号0~n-1, h[i]是第i个人的身高, v[i]是第i个人的分数, 要求从左到右选出一个子序列,在这个子序列中的人,从左到右身高是不下降的。
- 自学HarmonyOS应用开发(53)- 获取当前位置
- 新型LaaS协议Elephant Swap给ePLATO提供可持续溢价空间
- CMake Tutorial 巡礼(0)_总述
- [MySQL series] MySQL database foundation
- postgresql日常运维技能,适合初学者
- npm ERR! code ENOTSUP npm ERR! notsup Unsupported engine for [email protected]: wanted: {“n
猜你喜欢
随机推荐
遇到bug的解决办法,测试再也不背锅了
测试员容易陷入的9大误区
【LeetCode每日一题】——404.左叶子之和
The range of motion of the robot
string replace spaces
App测试需要测什么
推荐系统:用户“行为数据”的采集【使用Kafaka、Cassandra处理数据】【如果与业务数据重合,也需要独自采集】
Selenium上传文件有多少种方式?不信你有我全
Minimum number to rotate array
Talk about the construction of the performance test environment
Detailed introduction to the usage of Nacos configuration center
How Navicat Connects to MySQL
泰克Tektronix示波器软件TDS520|TDS1001|TDS1002上位机软件NS-Scope
新型LaaS协议Elephant Swap给ePLATO提供可持续溢价空间
SSM integration case
Fabric Writing Case Chaincode
STM32 - OLED display experiment
It is really strong to apply the @Transactional transaction annotation to such perfection!
STM32——OLED显示实验
液压滑环的应用介绍









