继续浏览精彩内容
慕课网APP
程序员的梦工厂
打开
继续
感谢您的支持,我会继续努力的
赞赏金额会直接到老师账户
将二维码发送给自己后长按识别
微信支付
支付宝支付

Vue2.0路由学习探索总结---嵌套路由

resharpe
关注TA
已关注
手记 102
粉丝 7244
获赞 3476
Vue2.0路由学习探索总结---嵌套路由
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>嵌套路由</title>
    <script src="../vue.js"></script>
    <script src="../vue-router.js"></script>
    <style>
        .router-link-active {
            color: red
        }
    </style>
</head>
<body>
<div id="app">
    <p>
        <router-link to="/user/foo">/user/foo</router-link>
        <router-link to="/user/foo/profile">/user/foo/profile</router-link>
        <router-link to="/user/foo/posts">/user/foo/posts</router-link>
    </p>
    <router-view></router-view>
</div>
</body>
<script>
    const User = {
        template: `
    <div class="user">
      <h2>User {{ $route.params.id }}</h2>
      <router-view></router-view>
    </div>
  `
    }
    const UserHome = {template: '<div>Home</div>'}
    const UserProfile = {template: '<div>Profile</div>'}
    const UserPosts = {template: '<div>Posts</div>'}
    const router = new VueRouter({
        routes: [
            {
                path: '/user/:id', component: User,
                children: [
                    {path: '', component: UserHome},
                    {path: 'profile', component: UserProfile},
                    {path: 'posts', component: UserPosts}
                ]
            }
        ]
    });
    const app = new Vue({router}).$mount('#app')
</script>
</html>
打开App,阅读手记
7人推荐
发表评论
随时随地看视频慕课网APP

热门评论

console.log("nice")


查看全部评论