Use dynamic components to create custom reusable transition components for Vue V3.
vue2-transitions
npm package uses the same method as below and it does not work with v3, So I decided to make a simple one for myself.
<component
:is="group ? 'transition-group' : 'transition'"
enter-active-class="fadeInDown"
leave-active-class="fadeOutUp"
>
<slot></slot>
</component>
<div>
<custom-transition>
<span v-if="show">This does not work.</span>
</custom-transition>
</div>
This does not work, I have no clue why. The <transition>
element is rendered like this.
<transition
enter-active-class="fadeInDown"
leave-active-class="fadeOutUp"
>
<span>This does not work.</span>
</transition>
When I rewrite the CustomComponent.vue
like this.
<transition
enter-active-class="fadeInDown"
leave-active-class="fadeOutUp"
>
<slot></slot>
</transition>
It is working perfectly fine.
I've Added a JSFiddle, in case someone wants to try something out.
Finally found the solution from vue community. link to working jsfiddle
For this component to work:
<component
:is="group ? 'transition-group' : 'transition'"
enter-active-class="fadeInDown"
leave-active-class="fadeOutUp"
>
<slot></slot>
</component>
Import the Transition
and TransitionGroup
components explicitly in the component and register them.
import { Transition, TransitionGroup } from 'vue'
export default {
components: {
Transition,
TransitionGroup,
},
data() {
return { show: false };
}
}
link to github issue in vue-next
repo.