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

vue会自动给vnode添加key吗? #341

Open
wisonxiang opened this issue Jun 18, 2024 · 1 comment
Open

vue会自动给vnode添加key吗? #341

wisonxiang opened this issue Jun 18, 2024 · 1 comment

Comments

@wisonxiang
Copy link

wisonxiang commented Jun 18, 2024

vue渲染器在更新列表时,会触发diff算法,diff算法依赖vnode上的key做算法优化。但在写模版时,除了v-for渲染列表会手写key。其他情况并不会去手写key,如:

<div id="parent">
    <h1 id="child">1</h1>
    <h1 id="child">2</h1>
    <h1 id="child">3</h1>
</div>
···
更新时也会触发diff算法?
@qinjialei24
Copy link

所有更新都会触发diff算法。
另外,Vue 不会自动为 VNodes 添加 key,你需要自己负责添加。如果省略 key,Vue 会尝试使用其他方式来识别节点,但这可能会导致性能问题,特别是在列表频繁更新的情况下。

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

2 participants