Vue学习

多个组件之间动画切换

2018-08-03  本文已影响0人  椰果粒

动态组件的方式

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>vue中的Js动画与velocity.js结合</title>
    <script src="https://unpkg.com/vue@2.5.16/dist/vue.js"></script>
    <style>
        .fade-enter, .fade-leave-to{
            opacity: 0;
        }
        .fade-enter-active, .fade-leave-active{
            transition: opacity 1s;
        }
    </style>
</head>
<body>
    <div id="app">
        <!-- 
            动态组件的方式
         -->
        <transition name="fade" mode="out-in">
            <component :is="type"></component>
        </transition>
        <button @click="handleChange">显示与隐藏</button>
    </div>
    <script>
        Vue.component('child-one',{
            template : "<div>child-one</div>"
        })
        Vue.component('child-two',{
            template : "<div>child-two</div>"
        })
        var vm = new Vue({
            el : "#app",
            data : {
                type : "child-one"
            },
            methods : {
                handleChange : function(){
                    this.type = this.type === "child-one" ? "child-two" : "child-one"
                },
                
            }
        })
    </script>
</body>
</html>
上一篇 下一篇

猜你喜欢

热点阅读