当前位置:网站首页>Data disorder occurs when the n-th row of the subcomponent list generated by V-for is deleted
Data disorder occurs when the n-th row of the subcomponent list generated by V-for is deleted
2022-06-13 07:45:00 【Niufenfen】
As shown in the following figure
After clicking the delete button , Data disorder occurs
Consult official documents , Found that when Vue Updating usage v-for
When rendering a list of elements , It uses by default “ in-place update ” The strategy of . If the order of data items is changed ,Vue Will not move DOM Element to match the order of data items , Instead, each element is updated in place , And make sure they render correctly at each index location .
This default mode is efficient , however Only applicable to non dependent sub component status or temporary DOM state ( for example : Form input value ) List render output for .
To give Vue A hint , So that it can track the identity of each node , To reuse and reorder existing elements , You need to provide a unique key
attribute:
Look at the code ,v-for Generated components , The binding is key May not be the only value , Can't bind index
So I gave it to v-for Component's key Bind a getTime(), Think of this every key The value will not be repeated , And it's the only one
After testing , Found deleted rows , The page data disorder is solved , But other problems arise , The cascade selector cannot be selected for the first time , The second time you can , After debugging, it is found that each operation of the cascade selector ,@change Bound functions console Will print twice . Add row each time , The data in the previous row will be empty , I can't figure it out , Another big circle ,
‘
collapsed 10 Minutes later , I went to check the official explanation ,key
Special attribute Mainly used in Vue The virtual DOM Algorithm , New and old nodes Identification in contrast VNodes. If not used key,Vue Will use a way to minimize dynamic elements and try to modify them in place as much as possible / Algorithms for reusing elements of the same type . While using key when , It will be based on key Changes to reorder elements , And it will be removed key Elements that do not exist .
Child elements with the same parent must have Distinctive key. Repetitive key Can cause rendering errors .
Found directly in dom It says in it getTime(), Of each generated component key It's all dynamic , Although every key It's all unique , But like this key It's meaningless , Every time key Changed , The element will be re rendered , So every time you add a row , The previous data is also empty , Every operation dom, All generate new , Instead of taking the old DOM To update the location , This will cause performance problems .
After modification, a unique... Is generated in the data key, And then in dom The binding , So there is no problem
link
边栏推荐
- Redis Cluster - the underlying principle of cluster execution commands
- Logback log framework learning and problems
- 力扣(LeetCode)163. 缺失的区间(2022.06.12)
- 分布式系统之道:Lamport 逻辑时钟
- MySQL table cache most detailed notes
- [log framework] add user-defined parameters to the MDC implementation log
- [tools for quickly creating MySQL stand-alone and cluster test environments] dbdeployer
- Redis underlying data structure - underlying principle of hash table
- [problem record] taberror: inconsistent use of tabs and spaces in indentation
- 比较DFS和BFS的优点和缺点及名称词汇
猜你喜欢
Selenium foundation API
安装CUDA+CUSP环境,并创建第一个HelloWord入门工程
MySQL table partitioning
Export chrome plug-ins and import local plug-ins to chrome
How app inventor accesses resource files in assets directory
[pytorch] pytorch0.4.0 installation tutorial and GPU configuration collection (including test code)
IIS中的网站访问excel
Redis master-slave replication - the underlying principle of partial resynchronization
Redis learning journey - transaction
GCC compilation process, function library related compilation process
随机推荐
在排序数组中查找元素的第一个和最后一个位置
Database outline
Success logarithm of leetcode spells and potions
Redis persistence -- AOF
Redis master-slave replication - underlying principle
[splashsplash] repeat the script that outputs splashsurf
Hashtable source code analysis
23 | 冒险和预测(二):流水线里的接力赛
Login registration
Simple use of logs
[log4j2 log framework] modify dump log file permissions
Data desensitization tool advance tool Datamask
socket编程2:IO复用(select && poll && epoll)
Learning notes of balanced binary tree -- one two pandas
力扣(LeetCode)163. 缺失的区间(2022.06.12)
First graphical interface (modified version)
24 | adventure and prediction (III): thread pool in CPU
Redis learning journey --redis Conf details
P6154 游走(记忆化搜索
IDS persistence ---rdb