天天看點

vue2.0學習筆記之路由(二)路由嵌套+動畫

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>vue2.0學習筆記之路由(二)路由嵌套+動畫</title>
    <link rel="stylesheet" href="animate.css">
</head>
<body>
    <div id="app">
        <div>
            <router-link to="/home">首頁</router-link>
            <router-link to="/user">使用者中心</router-link>
        </div>
        <div>
            <router-view></router-view>
        </div>
    </div>
</body>
</html>      
<script src="vue.js"></script>
<script src="vue-router.js"></script>
<script>
    // 定義元件
    var Home = {
        template:`
            <transition enter-active-class="animated bounceInLeft" leave-active-class="animated bounceOutRight">
                <h3>首頁内容</h3>
            </transition>
        `
    }
    var User = {
        template:`
            <div>
                <transition enter-active-class="animated bounceInLeft" leave-active-class="animated bounceOutRight">
                    <h3>使用者中心</h3>
                </transition>
                <ul>
                    <li><router-link to="user/userinfo">檢視個人資訊</router-link></li>
                </ul>
                <div>
                    <router-view></router-view>
                </div>
            </div>

        `
    }
    var UserDetail = {
        template:"<h4>個人資訊</h4>"
    }
    // 配置路由
    const routes = [
        { path:"/home", component:Home },
        {
            path:"/user",
            component:User,
            children:[
                { path:"userinfo",component:UserDetail }
            ]
        },
        { path:"*", redirect:"/home" } // 重定向讓頁面加載即顯示Home
    ]
    // 生成路由執行個體
    const router = new VueRouter({
        routes
    })
    // 挂載到vue執行個體上
    new Vue({
        el:"#app",
        router
    })
</script>      

轉載于:https://www.cnblogs.com/hcxy/p/7118739.html

繼續閱讀