vue中css的动画原理

<style>
        .fade-enter{
            opacity:0;
        }
        .fade-enter-active{
            transition: opacity 4s;
        }
        .fade-leave-to{
            opacity:0;
        }
        .fade-leave-active{
            transition: opacity 3s;
        }
    </style>
</head>
<body>
    <div id="root">
        <transition name="fade">    
            <div v-if="show">hello world</div>
        </transition>
        <button @click='handleClick'>切换</button>
    </div>

    <script>
        var vm = new Vue({
            el: "#root",
            data: {
                show: true
            },
            methods: {
                handleClick: function() {
                    this.show = !this.show
                }
            }
        })
    </script>

</body>

如图所示

猜你喜欢

转载自blog.csdn.net/twinkle_j/article/details/81130388