对路由传参的总结,不对之处望包涵,指正。记录
Vue路由传参的两种方式query 和 params
this.$route.query<router-link to='/home?id=123&name=zhangsan'>路由传参 query</router-link>
this.$route.query.id,即可拿到123,此api无需配置路由规则
this.$route.query.name,即可拿到,zhangsan此api无需配置路由规则
<router-link to="/home/123/zhangsan">路由传参 params</router-link>
this.$route.params.id,不可以拿到 123,都需要配置路由规则为:{path:'/home/:id/:name',Component:home}this.$route.params.name,也拿不到zhangsan,都需要配置路由规则为:{path:'/home/:id/:name',Component:home}这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。
V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。
V2EX is a community of developers, designers and creative people.