Vue学习

多个标签之间动画切换

2018-08-03  本文已影响1人  椰果粒
<!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">
        <!-- 
            mode : 
                in-out
                out-in
         -->
        <transition name="fade" mode="in-out">
            <!-- key值为了不复用DOM -->
            <div v-if="show" key="hello">Hello world</div>
            <div v-else key="bye">Bye world</div>
        </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 : {
                show : true
            },
            methods : {
                handleChange : function(){
                    this.show = !this.show
                },
                
            }
        })
    </script>
</body>
</html>
上一篇下一篇

猜你喜欢

热点阅读