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-once的使用场景有哪些? #114

Open
GGXXMM opened this issue Mar 17, 2022 · 0 comments
Open

v-once的使用场景有哪些? #114

GGXXMM opened this issue Mar 17, 2022 · 0 comments
Labels

Comments

@GGXXMM
Copy link
Owner

GGXXMM commented Mar 17, 2022

v-once

只渲染元素和组件一次。随后的重新渲染,元素/组件及其所有的子节点将被视为静态内容并跳过。

https://cn.vuejs.org/v2/api/#v-once

使用场景

1、低开销的静态组件

基本不会重新渲染的组件,可以加上 v-once 指令,用来优化更新性能。

<div v-once>
      <h1>Terms of Service</h1>
      ... a lot of static content ...
 </div>

2、一次性插值

通过使用 v-once 指令,可以执行一次性地插值,当数据改变时,插值处的内容不会更新。

<span v-once>这个将不会改变: {{ msg }}</span>
@GGXXMM GGXXMM added the vue label Mar 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant