使用this.$route.params接收的参数为undefined


问题:

使用this.$router.push跳转页面并用params方式传参,能够跳转页面但是使用this.$route.params接收的参数为undefined

 

原因:

在传参的页面中的this.$router.push使用了path而不是name,因为params只能用name来引入路由,不然接收参数会出现undefined

 

错误用法:

methods:{
  jump (){
    this.$router.push({path: '/xxx/login',params:{ id:'1'}});

  }

}

 

正确用法:

methods:{
  jump (){
    this.$router.push({name: 'login',params:{ id:'1'}});

  }

}

 

这里的name指路由中的name,比如路由中是:

{
title: '登录',

path: '/xxx/login',

name: 'login',

component: () => import('@/xxx/xxx/xxx')

}

那么name就是login


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM