vue.js-基于URL查询参数定义VUE路线的路径
假设我有这个URL http:// localhost:8080/public/form?code = fhuz15ahy
我已经在我的route.js
文件中定义了一条路由,例如
{
path: '/public/form?code=:code',
name: 'survey',
component: () => import('./views/form')
}
,应该重复使用相同的组件基于代码
查询来自URL的参数。
在我的form.vue
组件中,我已经定义了这样的道具:
props: {
code: {
type: String,
required: true
}
}
但这是不起作用的,因为我没有重定向到任何页面。
我认为我在定义路线的路径方面做错了。我该如何实现?
Let's assume I have this URLhttp://localhost:8080/public/form?code=fhuZ15aHy
I have defined a route in my route.js
file like this
{
path: '/public/form?code=:code',
name: 'survey',
component: () => import('./views/form')
}
which is supposed to reuse the same component based on the code
query parameter coming from URL.
In my form.vue
component I have defined a prop like this:
props: {
code: {
type: String,
required: true
}
}
But this is not working, in the sense that I am not redirected to any page.
I think I'm doing wrong with how I defined the path of the route. How can I achieve this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
请勿在路径中定义查询,
您应该像这样编写:
在组件中,您可以访问这样的查询
Do not define the query within the path
You should write like this:
And within the component you can access the query like this