0

I would like to be able to switch between transition A and B dynamically

Parent component

<child></child>

Child component

Transition A

<transition name="fade">
    <p v-if="show">hello</p>
</transition>

.fade-enter-active, .fade-leave-active {
  transition: opacity .5s
}
.fade-enter, .fade-leave-to /* .fade-leave-active in <2.1.8 */ {
  opacity: 0
}

Transition B (using animate.css library)

 <transition
    name="custom-classes-transition"
    enter-active-class="animated tada"
    leave-active-class="animated bounceOutRight"
  >
    <p v-if="show">hello</p>
  </transition>
3
  • I can see this working here, Can you reproduce your case? Commented Feb 17, 2017 at 5:42
  • The thing is instead of just changing the name of the transition I would like to use custom class for one but no for the other. First transition would be a transtition with name fade. The second transition would use custom class, like SlideInUp from animate.css Commented Feb 17, 2017 at 13:45
  • Somehting like that : fiddle.jshell.net/j9h3Lmr5 (it is not working) Commented Feb 17, 2017 at 13:55

1 Answer 1

2

You can do the dynamic transition with properly assigning the enterClass and leaveClass. Here is the working demo: https://fiddle.jshell.net/j9h3Lmr5/1/

JS:

var vm = new Vue({
  el: '#vue-instance',
  data: {
    show: true,
    transitionType: "fade",
    enterClass: "fade-enter",
    leaveClass: "fade-enter-active"
  },
  methods: {
    changeTransition() {
      if (this.transitionType === "fade") {
        this.transitionType = "custom-classes-transition"
        this.enterClass = "animated slideInUp"
        this.leaveClass = "animated slideOutDown"
      } else {
        this.transitionType = "fade"
          this.enterClass = "fade-enter"
          this.leaveClass = "fade-enter-active"
      }
    }
  }
});
Sign up to request clarification or add additional context in comments.

1 Comment

That's exactly what I was confused about ! Thanks a lot

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.