使用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