transition多组件过度-购物页面切换

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>Examples</title>
    <style type="text/css">
        * {
            margin: 0px;
            padding: 0px;
        }
        html,
        body {
            width: 100%;
            height: 100%;
            overflow-y: hidden;
        }
        footer ul {
            display: flex;
            position: fixed;
            left: 0px;
            bottom: 0px;
            width: 100%;
            height: 40px;
        }
        footer ul li {
            flex: 1;
            text-align: center;
            list-style: none;
            height: 40px;
            line-height: 40px;
            background: gray;
        }

        .bounce-enter-active {
            animation: bounce-in .5s;
        }

        .bounce-leave-active {
            animation: bounce-in .5s reverse;
        }

        @keyframes bounce-in {
            0% {
                transform: translateX(100px);
                opacity: 0;
            }
            100% {
                transform: translateX(0px);
                opacity: 1;
            }
        }
    </style>
</head>
<body>
    <div id="box">
        <keep-alive>
            <transition name="bounce" mode="out-in">
                <component :is="who"></component>
            </transition>
        </keep-alive>
        <footer>
            <ul>
                <li><a @click="who='home'">首页</a></li>
                <li><a @click="who='list'">列表页</a></li>
                <li><a @click="who='shopcar'">购物车页面</a></li>
            </ul>
        </footer>
    </div>

    <script src="http://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
    <script type="text/javascript">
        var vm = new Vue({
            el: "#box",
            data: {
                who: 'home'
            },
            components: {
                "home": {
                    template: `<div>home<input type="text"/></div>`
                },
                "list": {
                    template: `<div>list</div>`
                },
                "shopcar": {
                    template: `<div>shopcar</div>`
                }
            }
        })
    </script>
</body>
</html>
发布了20 篇原创文章 · 获赞 0 · 访问量 86

猜你喜欢

转载自blog.csdn.net/qq_46606159/article/details/105032893