首页 > 其他 > 详细

Vue Router中调用this.$router.push() 时,location使用path无法传入params

时间:2021-02-19 13:30:50      阅读:26      评论:0      收藏:0      [点我收藏+]

Vue Router中调用this.$router.push() 时,location使用path无法传入params

解决方法:

给动态路由取名字,然后在location中使用name指向路由的名字,这样就可以通过params传参数

下面这段是来自Vue Router的官网的代码

const userId = ‘123‘
router.push({ name: ‘user‘, params: { userId } }) // -> /user/123
router.push({ path: `/user/${userId}` }) // -> /user/123
// This will NOT work
router.push({ path: ‘/user‘, params: { userId } }) // -> /user

Vue Router中调用this.$router.push() 时,location使用path无法传入params

原文:https://www.cnblogs.com/Blithe-Chiang/p/14415275.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!