当前位置:网站首页>Why can't index be the key of V-for?
Why can't index be the key of V-for?
2022-07-24 06:37:00 【Slugs are not alone】
index Why not as v-for Of key?
One 、 Why use key?
key The main function of is to update the virtual database efficiently DOM.
for example , stay B and C Insert between F:
Diff The default execution process of the algorithm :
This kind of practice C Update to F,D Update to C,E Update to D, Finally, insert E, This is not efficient , And the performance is not good enough .
But if you use key Give each node a unique identification ,Diff The algorithm can correctly identify this node , Find the right place to insert a new node .

Two 、index Why not as v-for Of key?
Take the following code for example , Delete 'one':
<template>
<div v-for="(item, index) in list" :key="index" >{
{item.num}}</div>
</template>
const list = [
{
id: 0,
num: "zero"
},
{
id: 1,
num: "one"
},
{
id: 2,
num: "two"
},
{
id:3,
num:"three"
}
];
Before deleting :
| key | id | index | num |
|---|---|---|---|
| 0 | 0 | 0 | zero |
| 1 | 1 | 1 | one |
| 2 | 2 | 2 | two |
| 3 | 3 | 3 | three |
After deleting :
| key | id | index | num |
|---|---|---|---|
| 0 | 0 | 0 | zero |
| 1 | 2 | 1 | two |
| 2 | 3 | 2 | three |
here , except zero Outside ,two and three Because it was found to be corresponding key The binding relationship of has changed , So it was re rendered , Easy to affect performance .
边栏推荐
- Quickly and simply set up FTP server, and achieve public network access through intranet [no need for public IP]
- [219] what is the difference between app testing and web testing?
- Leetcode sword finger offer jz23: the entry node of the link in the linked list
- RESTful API介绍
- Crud of MySQL
- United Nations agricultural products data analysis
- Homework in the second week
- 使用自定义zabbix包(4.0.5版本)安装agent和proxy
- A batch of interview questions and answers_ 20180403 latest arrangement
- JSP tag
猜你喜欢

Website B video is embedded in the web page, and relevant controls are hidden

Leetcode sword finger offer jz73 flip word sequence

系统安全及应用

Do not rent servers, build your own personal business website (4)

JSP tag 02
![[214] what is an automation framework](/img/bb/24c35613c49357258876ce3f1611ee.jpg)
[214] what is an automation framework

Function application of MySQL

RAID5和LVM组合使用
![[222] memory overflow and location](/img/d8/a367c26b51d9dbaf53bf4fe2a13917.png)
[222] memory overflow and location

United Nations agricultural products data analysis
随机推荐
object-oriented
进行挂载永久挂载后无法开机
FTP服务与实验
文件系统与日志分析
mysql 忘记退出直接关闭窗口现在要删除整个文件夹如何删除
Batch implementation of key based authentication using sshpass
Flex layout
Leetcode does not add, subtract, multiply, divide, and calculate the number of 1 in binary
Solution of forgetting root password in mysql5.7 under Windows
[award issuance] the results of the first essay solicitation activity in oneos zone were announced
NFS shared services and experiments
General paging 2.0
Unable to boot after permanent mounting
力扣986.区间列表的交集
Restful API introduction
系统安全及应用
Life warning Maxim
Go environment construction and start
Remember to get the password of college student account once, from scratch
PXE technology network installation