美文网首页Vue
vue多个元素或多组件的过度

vue多个元素或多组件的过度

作者: 程序员同行者 | 来源:发表于2018-07-25 13:13 被阅读1次
<!DOCTYPE html>
<html>
<head>
    <title>vue多个元素或多组件的过度</title>
    <script src="./vue.js"></script>
<style>
        
        .v-enter,
        .v-leave-to {
            opacity: 0;
        }
        .v-enter-active,
        .v-leave-active {
            transition: opacity 2s;
        }
        
    </style>
</head>
<body>
<div id='app'>
    <!-- // 多元素过度 -->
    <transition 
            mode="out-in"
        >
    <div v-if="show" key="hello">hello world</div>
    <div v-else key="bye">Bye</div>
    </transition>
    <button @click='handleClick'>切换</button>
</div>

<!-- // 多组件过度 -->
<div id='app-1'>

    <transition 
            mode="out-in"
        >

        <component :is="type"></component>
        <!-- // 原生组件 -->
    <!--    <child v-if="show"></child>
        <child-one v-else></child-one> -->
    </transition>
    <button @click='handleClick'>切换</button>
</div>
<script>
    
    var vm1 =  new Vue({
        el: '#app',
        data: {
            show: true
        },
        methods: {
            handleClick: function() {
                this.show = !this.show
            }
        }
        
        
    })


    Vue.component('child',{
        template: '<div>child</div>'
    })
    Vue.component('child-one',{
        template: '<div>child-one</div>'
    })
    var vm2 =  new Vue({
        el: '#app-1',
        data: {
            // show: true
            type: 'child'
        },
        methods: {
            handleClick: function() {
                // this.show = !this.show
                this.type = this.type === 'child' ? 'child-one' : 'child'
            }
        }
        
        
    })
    
</script>
</body>
</html>

相关文章

网友评论

    本文标题:vue多个元素或多组件的过度

    本文链接:https://www.haomeiwen.com/subject/vzxsmftx.html