Vue Animation-Principles of CSS Animation in Vue (5-1)

Vue Animation-Principles of CSS Animation in Vue

If you check the two forms, you will find that the .v is the default, and you can also set the animation effect with name binding.

<style>
        .fade-enter,
        .fade-leave-to {
     
     
            opacity: 0;
        }
        .fade-enter-active,
        .fade-leave-active {
     
     
            transition: opacity 1s;
        }
    </style>
     <div id="root">
        <transition name="fade">
            <div v-if="show">hello world</div>
        </transition> 
       
        <button @click="handleClick">切换</button>
    </div>    
<!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 name="fade">
            <div v-if="show">hello world</div>
        </transition> -->
        <transition>
            <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>
</html>

Guess you like

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