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 v-show 和 v-if 的区别 #129

Open
GGXXMM opened this issue Apr 2, 2023 · 0 comments
Open

Vue v-show 和 v-if 的区别 #129

GGXXMM opened this issue Apr 2, 2023 · 0 comments
Labels

Comments

@GGXXMM
Copy link
Owner

GGXXMM commented Apr 2, 2023

区别

  • v-show 是简单切换元素的 CSS display属性,显示 or 隐藏
  • v-if 是“真正”的条件渲染,条件块内的事件监听器和子组件适当地销毁 or 重建

v-if 也是有惰性的,渲染条件为假,什么都不做,直至条件为真才开始渲染条件块。

总结

一般来说,v-if 有更高的切换开销,而 v-show 有更高的初始渲染开销。因此,如果需要非常频繁地切换,则使用 v-show 较好;如果在运行时条件很少改变,则使用 v-if 较好。

@GGXXMM GGXXMM added the vue label Apr 2, 2023
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