vue-router使用props传递参数的三种方法
1. props值为对象写法
{
path:"/home",
component:Home,
children:[
name:'detail',
path:'detail',
component:Detail,
props:{a :1,b:'hello'}
]
}
//接受
props:['a','b']
传递的参数是固定值
2. props值为boolean写法
{
path:"/home",
component:Home,
children:[
name:'detail',
path:'detail',
component:Detail,
props:true
]
}
//接受
props:['id','title']
只能传递params参数
3. porps值为函数的写法
{
path:"/home",
component:Home,
children:[
name:'detail',
path:'detail',
component:Detail,
//props($route){
// return {id:$route.query.id,title:$route.query.name}
//}
//props({query}){
// return {id:query.id,title:query.name}
//}
props({params}){
return {id:params.id,title:params.name}
}
]
}
//接受
prop:['id','title']