[英]Vue router with sub path
I have following component for the url:我有以下 url 组件:
{
path: '/resetpassword',
name: 'view-resetpassword',
component: ViewResetPassword,
},
And it gets opened when I enter localhosst:8080/resetpassword
当我输入
localhosst:8080/resetpassword
时它会打开
My question is how to access parameters that are given in that way:我的问题是如何访问以这种方式给出的参数:
localhost:8080/resetpassword/53c957fe-bbc2-4b32-8ebd-a84d79f7ffd2
I know, that I can access URL paramaters ?key=value
with this.$route.query.key
in the code.我知道,我可以在代码中使用
this.$route.query.key
访问 URL 参数?key=value
。 But how do I access parameter /...
?但是我如何访问参数
/...
?
You can use, like this你可以像这样使用
{ name: 'Projeto', path: '/projeto/:id', component: Projeto, meta: { public: true } }
with the:(the name), in the component:使用:(名称),在组件中:
this.$route.params.id
In my example is id, but you can put another name在我的示例中是 id,但您可以输入其他名称
Set your router to:将您的路由器设置为:
{
path: '/resetpassword/:token?',
name: 'view-resetpassword',
component: ViewResetPassword,
},
That route now can have optional token
param ( ?
is for the optional).该路由现在可以具有可选的
token
参数( ?
是可选的)。 Then you can access it on your component然后你可以在你的组件上访问它
this.$route.params.token
You can also pass it as a props instead, by adding props: true
on the router您也可以通过在路由器上添加
props: true
来将其作为道具传递
{
path: '/resetpassword/:token?',
name: 'view-resetpassword',
component: ViewResetPassword,
props: true
},
and on your component在你的组件上
export default {
...
props: ["token"];
...
}
then you can access the props然后你可以访问道具
this.token
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.