美文网首页
05_04.router-link标签

05_04.router-link标签

作者: Robyn_Luo | 来源:发表于2017-11-18 21:33 被阅读0次
    1. 代码演示
    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <meta http-equiv="X-UA-Compatible" content="ie=edge">
        <title>Document</title>
    </head>
    <body>
        <div id="app">
            {{ msg }}
            <!-- 路由占位 -->
            <router-view></router-view>
            <nav>
                <a href="#/login?name=zhangsan&age=17">登陆</a>
                <a href="#/register">注册</a>
                <a href="#/detail/abc/acb/abc/10/20">详情</a>
            </nav>
            <nav>
                <router-link v-bind:to="login">登陆</router-link>
                <router-link to="/register">注册</router-link>
                <router-link v-bind:to="{ name: 'xl', params: { id: 10, uid: 20 } }">详情</router-link>
            </nav>
        </div>
    
        <script src="vue.js"></script>
        <script src="vue-router.js"></script>
    
        <script>
    
            // 登陆组件配置项
            var LoginComponent = {
                template: `<div>{{ msg }}</div>`,
                data() {
                    return { 
                        msg: "我是登陆页面",
                    };
                }
            };
    
            // 注册组件配置项
            var RegisterComponent = {
                template: `<div>{{ msg }}</div>`,
                data() {
                    return { msg: "我是注册页面" }
                }
            };
    
            // 详情组件配置项
            var DetailComponent = {
                template: `<div>{{ msg }}</div>`,
                data() {
                    return { msg: "我是详情页面" }
                }
            };
    
            var vm = new Vue({
                el: '#app',
                data: {
                    msg: '路由演示',
                    login: {
                        path: '/login',
                        query: {
                            name: 'zhangsan',
                            age: 16
                        }
                    }
                },
                // 路由配置
                router: new VueRouter({
    
                    // 路线配置
                    routes: [
                        { path: '/login', component: LoginComponent },
                        { path: '/register', component: RegisterComponent },
                        { name: 'dl', path: '/detail/abc/abc/abc/:id/:uid', component: DetailComponent }
                    ]
                }),
    
                // 组件初始化完毕, 数据也绑定完毕后执行
                created() {
                    console.log(this);
                }
            });
        </script>
    </body>
    </html>
    

    相关文章

      网友评论

          本文标题:05_04.router-link标签

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