Using the <Transition> component with a component having v-if and v-else on root elements
Vue version
3.3.7
Link to minimal reproduction
Steps to reproduce
Click a toggle button.
What is expected?
A or B in the <TwoElements> component disappears in 2 seconds and appears in 2 seconds like A in the <OneElement>.
What is actually happening?
A or B in the <TwoElements> component disappears immediately and appears in 2 seconds.
System Info
System:
OS: macOS 13.5.2
CPU: (10) arm64 Apple M1 Max
Memory: 32.77 GB / 64.00 GB
Shell: 5.9 - /bin/zsh
Binaries:
Node: 18.15.0 - /usr/local/bin/node
Yarn: 1.22.10 - /usr/local/bin/yarn
npm: 9.5.0 - /usr/local/bin/npm
pnpm: 7.28.0 - /usr/local/bin/pnpm
Watchman: 4.9.0 - /usr/local/bin/watchman
Browsers:
Chrome: 118.0.5993.117
Edge: 118.0.2088.69
Safari: 16.6
npmPackages:
vue: ^3.3.7 => 3.3.7
Any additional comments?
No response
This is a known change between Vue 2 and Vue 3 - in Vue 3, the transition can only be triggered by v-if
or v-show
in the same template with the <transition>
component. This is intended behavior.
here is a workaround: add a dynamic key. see demo
<Transition mode="out-in">
<TwoElements :key="+toggle" :toggle="toggle" />
</Transition>