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

154.[vue]Vue 中v-if和v-for哪个优先级高?如果两个同时出现,应该怎么优化得到更好的性能? #154

Open
webVueBlog opened this issue Apr 2, 2020 · 1 comment
Labels
vue vue

Comments

@webVueBlog
Copy link
Member

[vue]

@webVueBlog webVueBlog added the vue vue label Apr 2, 2020
@webVueBlog
Copy link
Member Author

处于同一节点时,v-for优先级更高,v-if会执行在每个循环中。
两个同时出现时分两种情况:
1:需要对数组里每一个元素进行判断,此时应使用计算属性,得到所有符合条件的元素数组,然后用v-for遍历新数组
2:需要根据条件跳过循环,此时应该将v-if置于外层元素(或)上

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

No branches or pull requests

1 participant