1. 配置路由,声明接收params参数
{
path: '/home',
component: Home,
children:[
{
path: '/news',
components: News,
},
{
path: '/message',
component: Message,
children:[
name: 'xiangqing',
path: 'detail/:id/:title', // 使用占位符声明接收params参数
component: Detail
]
}
]
}
2. 传递参数
//跳转并携带params参数,to的字符串写法
<router-link :to="home/message/detail/${m.id}/${m.title}">跳转</router-link>
//跳转并携带params参数,to的对象写法
<router-link
:to="{
name: 'xiangqing',
params:{
id: m.id,
title: m.title
}
}">
跳转
</router-link>
特别注意: 路由携带params参数时,若使用to的对象写法,则不能使用path配置项,必须使用name配置!!!
3. 接收参数
$route.params.id
$route.params.title
本文介绍了在Vue.js的路由配置中如何声明和接收params参数,包括在父路由和子路由中的使用。通过`router-link`组件,可以使用字符串或对象写法传递参数。接收参数时,通过`$route.params`访问。
1万+

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



