美文网首页
2018-09-27 路由的那些事

2018-09-27 路由的那些事

作者: Stysteve丶雷 | 来源:发表于2018-09-27 07:33 被阅读0次

htttp-server:提取后台资源

$route.query;params 获取标签内的属性

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
</head>
<body>
   <div id='app'>
       <router-link to='/home'>首页</router-link>
       <router-link to='/user'>用户页</router-link>
       
        <router-view></router-view>
   </div>
    <script src='js/vue.js'></script>
    <script src='js/vue-router.js'></script>
    <script>
       //2
        var Home={
            template:`
             <div>我是首页</div>
            `
        }
         var User={
            template:`
             <div>

                  我是用户页
                 <p>
                    <router-link to='/user/regist?uname=jack&upwd=123'>注册</router-link>
                  </p>
                 <p>
                    <router-link to='/user/login/rose/456'>登录</router-link>
                  </p>
                   <router-view></router-view>
             </div>
            `
        }
        var Regist={
            template:`
               <div>
               <h1>这是注册页面</h1>
               <a href="">{{$route.query}}</a>
               <a href="">uname:{{$route.query.uname}}</a>
               <a href="">upwd:{{$route.query.upwd}}</a>
              </div>
             `
        } 
         var Login={
            template:`
                 <div>
                   <h1>这是登录页面</h1>
                   <a>{{$route.params}}</a>
                   <a>{{$route.params.uname}}</a>
                   <a>{{$route.params.upwd}}</a>
                 </div>
                `
        }  
      
         const routes=[
             {path:'/',component:Home},
             {path:'/home',component:Home},
             {
                 path:'/user',
                 component:User,
                 children:[
                     {path:'regist',component:Regist},
                     {path:'login/:uname/:upwd',component:Login}
                 ]
             }
         ]
       //4.创建实例
         const router=new VueRouter({
             routes:routes
         })
         
         
      new Vue({
          el:"#app",
          router:router
      })
    </script>
</body>
</html>

相关文章

网友评论

      本文标题:2018-09-27 路由的那些事

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