我想知道是否可以在vue-router的元数据字段中使用path
中的参数。例如,这里我在entity_id
中使用参数path
。但是,我还想将该参数用作meta
属性中的属性/参数,以便我可以更轻松地使用它:
{
path : ':entity_id',
name : 'DashboardEntity',
component: DashboardEntity,
meta : {
label: 'Example',
iwantthistobetheid: ':entity_id'
},
},
原因是我有一个面包屑文件,列出了路线/孩子/等。我想在面包屑中显示ID。
我可以在上面的示例中通过在面包屑视图中使用this.$route.params.entity_id
来做到这一点。但是,我必须将路由中的每个参数命名为类似id
的通用名称,以使其每次都能显示。
关于这怎么可能的解决方案,或者不需要我重命名所有路由器参数或不需要很大/如果要检查在我的面包屑视图中显示的每个路由器参数的解决方案,就不需要我?
您应该可以执行此操作:
this.$route.params[this.$route.meta.iwantthistobetheid]
相当于
this.$route.params.entity_id
或者如果iwantthistobetheid
= 'object_id'
this.$route.params.object_id