Vue: When v-if and v-show are used on the same element, leave transition does not occur when v-if changed to false

Created on 1 Dec 2016  Â·  5Comments  Â·  Source: vuejs/vue

Vue.js version

2.1.3

Reproduction Link

http://codepen.io/weotch/pen/GNyWaV

Steps to reproduce

Go to that codepen and click both links for "show" and "if" to "yes". Toggle just "show" off, note the transition occurs. Toggle "show" back on and then toggle "if" off, note that there is no transition out.

What is Expected?

I expected to still see the box transition out. Or, in other words, anenter transition should trigger only if both v-show and v-if == true. And a leave transition should trigger only if either v-show or v-if != true.

What is actually happening?

If v-if == true and v-show changes from true to false, the leave transition occurs as expected. If v-show== true and v-if changes from true to false, the element is immediately removed, no transition occurs.

My use case for this is using both v-if and v-show around media (img, video). The v-if triggers a load to start and then, once they are loaded, the v-show triggers the element to be revealed.

Most helpful comment

v-if and v-show are not supposed to be used together for transition purposes, because they entail conflicting start/ending states. Regarding your use case: you can use the v-if on the outer <transition> component instead.

All 5 comments

v-if and v-show are not supposed to be used together for transition purposes, because they entail conflicting start/ending states. Regarding your use case: you can use the v-if on the outer <transition> component instead.

Appreciate the feedback and thanks for that suggestion.

Can they use together now !? In Vue 2.x version.

@sky790312 the above was for Vue 2.x (2.1.3)

Got it. Thanks!

Was this page helpful?
0 / 5 - 0 ratings