query参数:
1 2 3 4 5 6 7 8
| <li v-for='m in messageList' :key='m.id'> <router-link :to=" { name:'messageDetail', query:{id:m.id,title:m.title} }">{{m.title}}</router-link> </li>
|
params参数:
1 配置路由声明接收param参数
1 2 3 4 5 6 7 8 9 10 11
| {path:'/home', component:Home, children:[ {path:'news', component:News}, {path:'message', component:Message, children:[ {path:'detail/:id/:title',name:'messageDetail',component:Detail} ]} ]},
|
2 传递参数
1 2 3 4 5 6 7 8 9 10
| <li v-for='m in messageList' :key='m.id'>
</li>
|
注意:路由携带params参数时,若使用to的对象写法,则不能使用path配置项,必须使用name配置项
props配置
1 2 3 4 5 6 7 8 9 10 11 12
| props:{a:1,b:'hello'},
props:true,
props($route){ return {id:$route.query.id,title:$route.query.title} },
props({query}){ return {id:query.id,title:query.title} }
|
Detail组件接收参数:
1 2 3 4 5 6
| <script> export default { name:'Detail', props:['id','title'], } </script>
|