What is the difference between v-show and v-if in Vue?

v-if is true conditional rendering, because it will ensure that the event listeners and subcomponents in the conditional block are properly destroyed and rebuilt during the switching process; it is also lazy: if the condition is false during the initial rendering, then nothing Don't do it-the conditional block will not be rendered until the condition becomes true for the first time.
v-show is much simpler-no matter what the initial conditions are, the element will always be rendered, and it is simply switched based on the CSS "display" property. Therefore, v-if is suitable for scenes that rarely change conditions during operation and do not need to switch conditions frequently; v-show is suitable for scenes that require frequent switching of conditions.

Guess you like

Origin blog.csdn.net/ni15534789894/article/details/112552877