美文网首页
vue零基础开发026——Vue中多个元素和组件的过渡

vue零基础开发026——Vue中多个元素和组件的过渡

作者: 文朝明 | 来源:发表于2019-12-11 15:17 被阅读0次

【多个元素过渡】

<html>
<head>
    <meta charset="utf-8" />
    <title>Vue中多个 元素和组件的过渡</title>
    <script src="./vue.js"></script>
    <script src="./velocity.js"></script>
    <style>
        .v-enter, .v-leave {
            opacity: 0
        }

        .v-enter-active, .leave-active {
            transition: opacity 1s
        }
    </style>
</head>
<body>
    <!--in-out 先显示再隐藏,out-in先隐藏 再显示-->
    <div id="root" mode="in-out">
        <transition>
            <div v-if="show" key="'hellow">hellow world</div>
            <div v-else track-by="bye">bye world</div>
        </transition>
        <button @click="handleClick">toggle</button>
    </div>
    <script>
        var vm = new Vue({
            el: "#root",
            data: {
                show: true
            },
            methods: {
                handleClick: function () {
                    this.show = !this.show
                },
            }
        })

    </script>
</body>
</html>
多个元素过渡

【多个组件过渡1】

<html>
<head>
    <meta charset="utf-8" />
    <title>Vue中多个 元素和组件的过渡</title>
    <script src="./vue.js"></script>
    <script src="./velocity.js"></script>
    <style>
        .v-enter, .v-leave {
            opacity: 0
        }

        .v-enter-active, .leave-active {
            transition: opacity 1s
        }
    </style>
</head>
<body>
    <!--in-out 先显示再隐藏,out-in先隐藏 再显示-->
    <div id="root" mode="in-out">
        <transition>
            <child v-if="show"></child>
            <child-one v-else></child-one>
        </transition>
        <button @click="handleClick">toggle</button>
    </div>
    <script>
        Vue.component('child', {
            template: '<div>child</div>'
        })
        Vue.component('child-one', {
            template: '<div>child-one</div>'
        })
        var vm = new Vue({
            el: "#root",
            data: {
                show: true
            },
            methods: {
                handleClick: function () {
                    this.show = !this.show
                },
            }
        })

    </script>
</body>
</html>

【多个组件过渡2】

<html>
<head>
    <meta charset="utf-8" />
    <title>Vue中多个 元素和组件的过渡</title>
    <script src="./vue.js"></script>
    <script src="./velocity.js"></script>
    <style>
        .v-enter, .v-leave {
            opacity: 0
        }

        .v-enter-active, .leave-active {
            transition: opacity 1s
        }
    </style>
</head>
<body>
    <!--in-out 先显示再隐藏,out-in先隐藏 再显示-->
    <div id="root" mode="in-out">
        <transition>
            <component :is="type"></component>
        </transition>
        <button @click="handleClick">toggle</button>
    </div>
    <script>
        Vue.component('child', {
            template: '<div>child</div>'
        })
        Vue.component('child-one', {
            template: '<div>child-one</div>'
        })
        var vm = new Vue({
            el: "#root",
            data: {
                /* show: true*/
                type: 'child'
            },
            methods: {
                handleClick: function () {
                    this.type = this.type === 'child' ? 'child-one' : 'child'
                },
            }
        })

    </script>
</body>
</html>

多个组件过渡

相关文章

网友评论

      本文标题:vue零基础开发026——Vue中多个元素和组件的过渡

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