### 6.路由的params参数
1. 配置路由,声明接收params参数
```js
{
path:'/home',
component:Home,
children:[
{
path:'news',
component:News
},
{
component:Message,
children:[
{
name:'xiangqing',
path:'detail/:id/:title', //使用占位符声明接收params参数
component:Detail
}
]
}
]
}```
2. 传递参数
```vue
<!-- 跳转并携带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配置!
3. 接收参数:
```js
$route.params.id
$route.params.title```
文章介绍了在Vue.js路由中如何声明并使用params参数,包括配置路由、通过to属性传递参数以及在组件内接收参数的方法。强调了使用对象写法时需用name而非path配置项。
840

被折叠的 条评论
为什么被折叠?



