vue_24 vue中的动画封装

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <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">
        <fade :show="show">
            <div v-if="show">miss you</div>
        </fade>
        <fade :show="show">
            <h1 v-if="show">miss you</h1>
        </fade>
        <button @click="handle">toggle</button>
    </div>


    <script>

    Vue.component('fade',{
        props:['show'],
        template:`
        <transition @before-enter="handleBeforeEnter" @enter="handleEnter">
            <slot v-if="show"></slot>
        </transition>
        `,
        methods:{
            handleBeforeEnter:function(el){
                el.style.color = 'red'
            },
            handleEnter:function(el,done){
                setTimeout(() =>{
                    el.style.color = 'green'
                    done()
                },2000)
            }
        }
    })  

    var vm = new Vue( {
        el: "#root",
        data: {
            show: false
        },
        methods: {
            handle: function() {
                this.show = !this.show
            },

        }
    })
    </script>
    
</body>
</html>

vue动画封装
vue动画封装
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容