1.查询字符串
用法:“路径”?uname=jack&age=123
接收:{{$route.query}}
2.rest风格传参
{{$route.params}}
1.效果
html部分
<div id='app'>
<router-link to='/home'>首页</router-link>
<router-link to='/user'>用户页</router-link>
<router-view></router-view>
</div>
js部分
<script>
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>
`
}
//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.创建实例
const router=new VueRouter({
routes:routes
})
new Vue({
el:"#app",
router:router
})
</script>