The difference between v-if and v-show

Source: Internet
Author: User
Tags event listener

In short, the v-if is initialized faster, but the switching cost is high; The v-show initialization is slow, but the switching costs are 1 lower. Common denominator

are dynamically displaying DOM elements 2. Differences

(1) means:
V-if is the dynamic addition or deletion of DOM elements to the DOM tree;
V-show is controlled by setting the display style property of the DOM element;
(2) Compile process:
The V-IF switch has a local compile/unload process that properly destroys and rebuilds the internal event listener and sub-components during the switchover process;
V-show is just a simple CSS-based switch;
(3) Compile condition:
The v-if is inert and does nothing if the initial conditions are false, and only when the condition first becomes true does it start the local compilation (the compilation is cached. After the compilation is cached, and then switch the time for partial uninstallation);
V-show is compiled under any conditions (whether the first condition is true), then cached, and the DOM element is preserved;
(4) Performance consumption:
The v-if has higher switching consumption;
V-show has higher initial rendering consumption;
(5) Use the scene:
V-if suitable operating conditions are unlikely to change;
The v-show is suitable for frequent switching.

For more information, please see the original http://www.cnblogs.com/wmhuang/p/5420344.html

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.