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

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
posted @ 2021-02-19 11:27  Blithe-Chiang  阅读(422)  评论(0编辑  收藏  举报