Interview Knowledge -vue-1

Difference 1.v-if's and v-show?

1) .v-show and v-if is used to display the hidden elements, v-if there is a v-else with the use of both to achieve the same effect.

Performance to a big difference:

2) .v-show: no matter the condition is true or false, for the first time rendering is going to be compiled, that is, the tag will be added to the DOM. Time after switching through display: none; style to show hidden elements. It can be said just change the css styles, almost does not affect any performance. v-if: the first time when rendering, if the condition is false, nothing to operate, as a page without those elements. When the condition is true, we began to compile local, dynamic add elements to the DOM element inside. When the condition becomes true from the false, began compiling local, uninstall these elements is removed.

3). Performance v-if performance is definitely more consumed, because v-if there DOM to add and delete hidden in the display process, v-show is much simpler, but the operation css.

4) Because v-show rendering anyway, if difficult to appear in some scenes, then use the v-if. If it is some fixed, the condition is not how the content will change, frequent switching, the use of v-show would be more time-saving features. If sub-assemblies, sub-assemblies each time you switch does not perform life cycle, using the v-show, if sub-assemblies need to perform life cycle, use the v-if fires.

Guess you like

Origin www.cnblogs.com/xiao-peng-ji/p/11809008.html