Transition of multiple elements or components in Vue (5-5)

Transition of multiple elements or components in Vue

mode="out-in" means first out and then in.

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src='./vue.js'></script>
    <style>
        .v-enter, .v-leave-to {
     
     
            opacity: 0;
        }
        .v-enter-active, .v-leave-active {
     
     
            transition: opacity 1s;
        }
    </style>
</head>
<body>
    
    <div id="root">
        <transition mode="out-in"> 
            <component :is="type"></component>
        </transition>
        <button @click="handleClick">toggle</button>
    </div>    

   <script>

       Vue.component('child', {
     
     
           template: '<div>child</div>'
       })

       Vue.component('child-one', {
     
     
           template: '<div>child-one</div>'
       })

       var vm = new Vue({
     
     
           el: '#root',
           data: {
     
     
               type: 'child'
           },
           methods: {
     
     
               handleClick: function() {
     
     
                   this.type = this.type === 'child' ? 'child-one' : 'child'
               }
           }
       })
      
    </script>
</body>
</html>

Guess you like

Origin blog.csdn.net/weixin_45647118/article/details/114027909
Recommended