The difference between v-if and v-show

the difference:
  • v-show displays and hides DOM by controlling the display attribute.
  • v-if is conditional rendering in the true sense. When it is true, it is rendered (dom exists), when it is false, it does not exist (dom does not exist).
performance:
  1. v-if has higher switching overhead, and v-show has higher initial rendering overhead.
    If frequent switching is required, it is better to use v-show. If the operating conditions rarely change, it is better to use v-if.
  2. v-show has higher performance than v-if because v-show can only dynamically change styles without adding or deleting DOM elements.
    Therefore, when the program is not very large, there is not much difference between v-if and v-show. If the project is very large, it is recommended to use v-show more, which will reduce the performance of the browser's later operations.
  3. When multiple condition scenarios are required, such as id=1, =2, =3..., because there is only v-if, it can be used in conjunction with v-else, etc. In this case, v-if is more suitable
  4. v-show does not support syntax
  5. When v-if switches, it will destroy and rebuild internal events, hook functions, etc. in real time. v-show will only be executed during initial rendering, and will not execute the later life process when switching.

Guess you like

Origin blog.csdn.net/shanghai597/article/details/131832281