[英]vue-router : use parameter in meta data?
I'm wondering if I can use the parameter from path
in vue-router's meta data field.我想知道我是否可以在 vue-router 的元数据字段中使用来自
path
的参数。 For instance, here I am using the parameter entity_id
in the path
.. but, I want to also use that parameter as a property/parameter in the meta
property so that I can use it more easily:例如,在这里我在
path
使用参数entity_id
.. 但是,我还想将该参数用作meta
属性中的属性/参数,以便我可以更轻松地使用它:
{
path : ':entity_id',
name : 'DashboardEntity',
component: DashboardEntity,
meta : {
label: 'Example',
iwantthistobetheid: ':entity_id'
},
},
The reason is that I have a breadcrumb file that lists out the routes/children/etc.原因是我有一个面包屑文件,列出了路线/孩子/等。 and I want to display the ID in the breadcrumb.
我想在面包屑中显示 ID。
I can do that in the above example by using this.$route.params.entity_id
in my breadcrumb view.. but then I have to name every parameter in my routes something generic like id
to have it display every time.我可以通过这样做,在上面的例子中
this.$route.params.entity_id
在我的面包屑观点..但后来我说出每个参数在我的路线一般的东西像id
通过它来显示每一次。
Any idea of how this might be possible or a solution that doesn't require me to either rename all my router parameters or have a huge if/else to check each routers params to display in my breadcrumb view?任何想法这可能是如何可能的,或者不需要我重命名所有路由器参数或有一个巨大的 if/else 检查每个路由器参数以显示在我的面包屑视图中的解决方案?
You should be able to do this:你应该能够做到这一点:
this.$route.params[this.$route.meta.iwantthistobetheid]
that would be the equivalent of这相当于
this.$route.params.entity_id
or if iwantthistobetheid
= 'object_id'
或者如果
iwantthistobetheid
= 'object_id'
this.$route.params.object_id
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.