如何获得具体信息,具体取决于我单击的项目?

时间:2019-04-08 11:49:50

标签: vue.js vue-router

我有一个显示用户项目的组件,事实是我想通过单击显示有关特定项目信息的项目名称来导航到新组件。因此,我想我需要创建一个组件,以便通过vue路由器接收所选项目的ID。

如何通过路由器链接将该项目ID发送到新页面,以呈现该信息?

也许将项目ID作为参数发送?

1 个答案:

答案 0 :(得分:0)

您可以在路线对象中使用:parameterName

const router = new VueRouter({
  routes: [
    { path: '/user/:id', component: User }
  ]
})

您可以使用 this。$ router.params.id

在组件中访问它

取决于您希望如何显示信息,可以使用<router-view>甚至嵌套的<router-view>来显示项目详细信息。可以在这里找到更多信息

https://router.vuejs.org/guide/essentials/dynamic-matching.html https://router.vuejs.org/guide/essentials/nested-routes.html