美文网首页
动态路由

动态路由

作者: 元宇宙编程 | 来源:发表于2020-01-09 16:07 被阅读0次
    动态路由:
    <!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>动态路由</title>
    </head>
    <body>
    <div id="app">
    <h1>Router 2</h1>
    <div>
        <router-link to="/user/think">Think</router-link>
        <router-link to="/user/dnedu">Dnedu</router-link>
    </div>
    <router-view></router-view>
    </div>    
    <script src="js/vue.js"></script>
    <script src="js/vue-router.js"></script>
    <script>
    let User = {
    template:`<div>User:{{$route.params.id}}</div>`,
    watch:{
        '$route'(to,from){
            console.log('从'+from.params.id+'到'+to.params.id);
        }
      }
    }
    let router = new VueRouter({
    routes:[
        //前面/user/后面任意
        {path:"/user/:id/",component:User}
    ]
    });
    const app = new Vue({router:router}).$mount("#app");
    </script>
    </body>
    </html>

    相关文章

      网友评论

          本文标题:动态路由

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