2

Goal:

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.

CustomTransition.Vue

<component
  :is="group ? 'transition-group' : 'transition'"
  enter-active-class="fadeInDown"
  leave-active-class="fadeOutUp"
>
  <slot></slot>
</component>

SomeOtherComponent.vue

<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>

But,

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.

Edit

I've Added a JSFiddle, in case someone wants to try something out.

3
  • please share the css Commented Sep 25, 2020 at 13:25
  • I am using animate.css for animations. I did not post the full name in above question, which doesn't really matter. Full name would be animate__animated animate__fadeInDown and animate__animated animate__fadeOutUp. Commented Sep 25, 2020 at 14:28
  • The issue seems to be with dynamic component <component :is="componentType">. It is working when i use names of global components that i've defined, but does not work with vue.js transition component. Commented Sep 25, 2020 at 14:31

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.