You must add a key to each div, in addition to adding vue 2.x in the fiddle, you need to make the following changes:
Why from docs
When switching between elements that have the same tag name, you must tell Vue that they are separate elements, providing them with unique key attributes. Otherwise, the Vues compiler will only replace the contents of the element with efficiency. Even when this is not technically necessary, its prudent practice should always include several elements within the component.
HTML
<transition name="fade"> <div key="3" v-if="show"> <div class="box yellow"></div> </div> </transition> <transition name="fade"> <div key="1" v-if="!show"> <div class="box blue"></div> </div> </transition>
Working fiddle: https://jsfiddle.net/k6grqLh1/21/
Edited
To make it smoother, you can use Transition-Modes : mode="out-in" , which first displays the current element, then when the full, new element goes to. see below code:
<transition name="fade" mode="out-in"> <div key="3" v-if="show"> <div class="box yellow"></div> </div> <div key="1" v-if="!show"> <div class="box blue"></div> </div> </transition>
Fiddle: https://jsfiddle.net/k6grqLh1/22/
source share