Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v-for中key的作用是什么? #2

Closed
qiufeihong2018 opened this issue Apr 19, 2019 · 0 comments
Closed

v-for中key的作用是什么? #2

qiufeihong2018 opened this issue Apr 19, 2019 · 0 comments

Comments

@qiufeihong2018
Copy link
Owner

key是为了提高diff算法找到对应节点的速度。
有时候没有key往往速度更快,那是因为没有key,组件也就没有唯一标识,页面可以‘就地复用’该组件,那么切换组件的速度就比有key标识快上很多。
但是会产生副作用。例如,不会产生过渡效果,当绑定数据出现状态错位。这个默认的模式是高效的,但是只适用于不依赖子组件状态或临时 DOM 状态 (例如:表单输入值) 的列表渲染输出

参考文献

vue官网

第一题:key的作用是为了在diff算法执行时更快的找到对应的节点,提高diff速度

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant