关于javascript:Vue路由传参

Vue路由传参

对路由传参的总结,不对之处望包涵,斧正。记录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,即可拿到,zhangsanapi无需配置路由规定
路由传参之——- `this.$route.params

<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}

评论

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

这个站点使用 Akismet 来减少垃圾评论。了解你的评论数据如何被处理