当前位置:网站首页>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;
边栏推荐
- 高德地图jsapi不生效 INVALID_USER_SCODE
- How Junior Testers Grow Fast
- 初级测试人员如何快速成长
- 【MySQL必知必会】 范式 | ER模型
- 性能测试理论1 | 性能测试难点问题梳理
- TCP/IP 常见问题
- Recommendation systems: feature engineering, common features
- 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]
- 9 common mistakes testers fall into
- jar包解压后再打包为jar
猜你喜欢

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

【Flutter】Flutter inspector 工具使用详解,查看Flutter布局,widget树,调试界面等

LeetCode / Scala - 无重复字符最长子串 ,最长回文子串

【LeetCode每日一题】——230.二叉搜索树中第K小的元素

How to realize the frame selection of objects in canvas (6)

【微服务~Nacos】Nacos服务提供者和服务消费者

string replace spaces

Linux-安装MySQL(详细教程)

日期时间存入数据库会差一天?

Leetcode69. x 的平方根
随机推荐
记笔记!电源自动测试系统测试电源纹波详细方法
Unity笔记——FairyGUI
新型LaaS协议Elephant Swap给ePLATO提供可持续溢价空间
It is really strong to apply the @Transactional transaction annotation to such perfection!
Navicat error: 1045-Access denied for user [email protected](using passwordYES)
Finding a 2D Array
机械设备制造企业如何借助ERP系统,解决成本核算难题?
初级测试人员如何快速成长
Object.freeze() learning
Replace the executable file glibc version of the one
npm ERR! code ENOTSUPnpm ERR! notsup Unsupported engine for [email protected]: wanted: {“n
Leetcode69. x 的平方根
Object.freeze()学习
Leetcode70. 爬楼梯
Nacos配置中心用法详细介绍
nacos集群配置详解
LeetCode / Scala - 无重复字符最长子串 ,最长回文子串
MySql的初识感悟,以及sql语句中的DDL和DML和DQL的基本语法
CMake Tutorial Tour(0)_Overview
ufw 设置防火墙规则