路由的params參數
-
配置路由,聲明接收params參數
{ path:'/home', component:Home, children:[ { path:'news', component:News }, { component:Message, children:[ { name:'xiangqing', path:'detail/:id/:title', //使用占位符聲明接收params參數 component:Detail } ] } ] }
-
傳遞參數
<!-- 跳轉並攜帶params參數,to的字符串寫法 --> <router-link :to="/home/message/detail/666/你好">跳轉</router-link> <!-- 跳轉並攜帶params參數,to的對象寫法 --> <router-link :to="{ name:'xiangqing', params:{ id:666, title:'你好' } }" >跳轉</router-link>
特別注意:路由攜帶params參數時,若使用to的對象寫法,則不能使用path配置項,必須使用name配置!
-
接收參數:
$route.params.id $route.params.title