当前位置:网站首页>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;
边栏推荐
猜你喜欢

Unity笔记——FairyGUI

LeetCode 2352. 相等行列对

exness: U.S. GDP shrinks, yen bounces back

Fabric Private Data Case

MATLAB被禁下一个会是LABVIEW吗?国产测试软件ATECLOUD崛起发力

How Navicat Connects to MySQL

What majors become more popular the older they get?

How many ways does Selenium upload files?I don't believe you have me

Self-study HarmonyOS application development (56) - Use Service to ensure that the application runs continuously in the background

遇到bug的解决办法,测试再也不背锅了
随机推荐
图解LeetCode——593. 有效的正方形(难度:中等)
神经网络迭代次数的一个近似关系
How to set up hybrid login in SQL server in AWS
在服务器上运行node流程
Navicat报错:1045-Access denied for user [email protected](using passwordYES)
泰克Tektronix示波器软件TDS210|TDS220|TDS224上位机软件NS-Scope
CMake Tutorial 巡礼(1)_基础的起点
Superficial understanding of CNN
Fabric 编写案例 链码
nacos的共享配置和扩展配置
【Vmware NSX-V基本架构及组件安装】
验证框架-01
Running a Fabric Application
【Flutter】Flutter inspector 工具使用详解,查看Flutter布局,widget树,调试界面等
Selenium上传文件有多少种方式?不信你有我全
npm ERR! code ENOTSUPnpm ERR! notsup Unsupported engine for [email protected]: wanted: {“n
05.script_setup中的私有属性
新型LaaS协议Elephant Swap给ePLATO提供可持续溢价空间
测试员容易陷入的9大误区
什么专业越老越吃香?