this.$router.push({
path: 'register',
name:'register',
params: { plan: 'private' }
}) 复制代码
这么写显然是不对的,对于this.$router.push()传参,我在项目通常使用如下两种方式:
一、使用params传参,例:前端
this.$router.push({ name: 'user', params: { userId: 123 }})复制代码
注意⚠️:patams传参 ,路径不能使用path 只能使用name,借用vue官方文档的一句话,this will not work。vue
获取参数,例:bash
this.$route.params.userId复制代码
二、使用query传参,例:this
this.$router.push({ path: '/user', query: { userId: 123}})
复制代码
注意⚠️:若是写成:spa
this.$router.push({ path: '/user', params: { userId: 123 }}) 复制代码
这样依然借用vue官方文档的一句话:this will not work。code
获取参数,例:router
this.$route.query.userId复制代码