路由的傳參:
1,查詢字符串:
路徑?uname=jack&upwd=123
接收:{{$route.query}}
2,rest風(fēng)格傳參
路徑/rose/456 在組件里面一一對(duì)應(yīng)
接收:{{$route.params}}
路由傳參:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<div id='app'>
<router-link to='/home'>首頁(yè)</router-link>
<router-link to='/user'>用戶頁(yè)</router-link>
<router-view></router-view>
</div>
<script src="../axios/js/vue.js"></script>
<script src="../axios/js/vue-router.js"></script>
<script>
//2
var Home={
template:`
<div>我是首頁(yè)</div>
`
}
var User={
template:`
<div>
我是用戶頁(yè)
<p>
<router-link to='/user/regist?uname=jack&upwd=123'>注冊(cè)</router-link>
</p>
<p>
<router-link to='/user/login/rose/456'>登錄</router-link>
</p>
<router-view></router-view>
</div>
`
}
var Regist={
template:`
<div>
<h1>這是注冊(cè)頁(yè)面</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>這是登錄頁(yè)面</h1>
<a>{{$route.params}}</a>
<a>{{$route.params.uname}}</a>
<a>{{$route.params.upwd}}</a>
</div>
`
}
//3.
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.創(chuàng)建實(shí)例
const router=new VueRouter({
routes:routes
})
new Vue({
el:"#app",
router:router
})
</script>
</body>
</html>