使用 vue-router 时可以有多个 id 路径吗?

问题描述 投票:0回答:1

有可能有这样的事情吗?

// router/index.js
const routes = [
  {
    path: '/books/:bookId/authors/:authorId',
    name: 'Author',
    props: true,
    component: () => import('@/views/AuthorView.vue')
  }
]

AuthorView.vue
中,我有一个面包屑组件,使用这些 id 可以很容易地填充它。我需要它们位于 URL 中,以允许用户复制和共享 URL。

编辑#1

这里官方文档的链接。

vuejs2 vue-router
1个回答
1
投票

路由声明正确,您可以使用 Author 组件中的 props 来访问 Id。

<script>    
export default {
    props :['bookId','authorId'],
};
</script>

路由器链接到页面

<router-link :to="{ name: 'Author', params: { bookId:bookId,authorId: authorId }}"  class="btn btn-sm btn-primary" variant="primary">Edit</router-link>
© www.soinside.com 2019 - 2024. All rights reserved.