The difference between v-if and v-show

1. Common points:


Both v-if and v-show can display and hide elements

Second, the difference:


    1. v-show simply controls the display attribute of the element, while v-if is conditional rendering (if the condition is true, the element will be rendered, if the condition is false, the element will be destroyed);

    2. v-show has a higher initial rendering overhead, while v-if's initial rendering overhead is much smaller;

    3. v-if has higher switching overhead, while v-show has lower switching overhead;

    4. v-if has matching v-else-if and v-else, but v-show does not

    5. v-if can be used with template, but v-show cannot

3. The usage scenarios of v-show and v-if


Both v-if and v-show can control the display of dom elements on the page

v-if is more expensive than v-show (directly operate dom node addition and deletion)

If you need to switch very frequently, it is better to use v-show

If the condition rarely changes at runtime, it is better to use v-if
 

Guess you like

Origin blog.csdn.net/qq_45947664/article/details/127601608