Vue router
params
1.配置路由,声明接收params参数
export default new VueRouter({ routes: [ { path: "/about", component: RouteAbout, }, { path: "/home", component: RouteHome, children: [ { path: "/home/news", component: RouteNews, }, {
name:"yyy" path: "/home/message", component: RouteMessage, children: [{ path: "/home/message/detail/:id/:title", //使用占位符声明接收params参数
component: RouteDetail }], }, ], }, ],{{}} });
2.传递参数
<router-link :to="`/home/message/detail/${p.id}/${p.title}`">{{p.title}}</router-link>
or
<router-link :to="{ name:'yyy', params: { id: p.id, title: p.title, }, }" ></router-link>
注:路由带params参数时,若使用to的对象写法,则不能使用path配置项,必须使用name
3.接收参数
$route.params.id
$route.params.title