如果要用 params 传参的话,可能需要在你的路由路径里也加上这个参数,比如你用
this.$router.push({name:'detail', params:{userId: userId}});跳转,那么在路由里就要这样写

   this.$router.push({name:'Detail',params:{pro_id:pro_id}});

router - index.js 路由设置,参数名保持一致。

{
      path: '/Detail/:pro_id',
      name: 'Detail',
      component: Detail
    },

 

其中这里的router里的 path:'/Detail/:pro_id',里的:pro_id 是必须要有的。方可保证页面在用户重新刷新后,页面的参数不会丢失报错

 

跳转后,获取参数:

console.log(this.$route.params.userId)

注意:是 $route   ......

 

 

具体的可以参考 Vue-router 命名路由

Logo

前往低代码交流专区

更多推荐