vue this.$router傳參與接收


this.$router.push({name:'/xx/xx',query: {id:'1'}});
this.$router.push({name:'/xx/xx',params: {id:'1'}});
this.$router.push({path:'/xx/xx',query: {id:'1'}});
this.$router.push({path:'/xx/xx',params: {id:'1'}});
1.query方式傳參和接受參數

this.$router.push({
 path:'/xxx'
 query:{
  idname:id
  }
})

接收的方式:this.$route.query
query類似於ajax中get傳參,即在瀏覽器地址欄中顯示參數。
2.params方式傳遞參數

this.$router.push({
 name:'路徑名稱'
 query:{
  idname:id
  }
})

接收的方式:this.$route.params
params則類似於post,即在瀏覽器地址欄中不顯示參數。
注意:

  • 接收是用this.$route,不是this.$router
  • params用的是name進行的傳遞,這就意味着在router的js文件里,要給其加上name屬性
    image


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM