How to use Vue.js transitions and animations?

To use transitions and animations in Vue.js, follow these steps:

  1. Install the Vue.js package via npm:

    npm install vue
  2. Add Vue.js to your HTML file:

    <script src="path/to/vue.js"></script>
  3. Create a Vue instance:

    new Vue({ el: '#app', data: { show: false } })
  4. Use the transition component to define a transition:

    <transition name="fade"> <p v-if="show">This will fade in and fade out</p> </transition>
  5. Define the CSS for the transition:

    .fade-enter-active, .fade-leave-active { transition: opacity .5s; } .fade-enter, .fade-leave-to { opacity: 0; }
  6. Alternatively, you can use pre-defined CSS classes for common transitions:

    <transition name="slide"> <!-- Content to be animated --> </transition> .slide-enter-active, .slide-leave-active { transition: all .5s; } .slide-enter, .slide-leave-to { transform: translateX(100px); opacity: 0; }
  7. To trigger the transition, modify the value of show property:

    this.show = true; // or false

Now, when the show property is true, the content within the transition component will be animated using the defined transition.