问题:
使用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