問題:
使用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