vue $router.push 傳參的問題


$router 和 $route的區別

  $route為當前router跳轉對象里面可以獲取name、path、query、params等

  $router為VueRouter實例,想要導航到不同URL,則使用$router.push方法

  返回上一個history也是使用$router.go方法

$router.push()

  1.params 傳參

    注意⚠️:patams傳參 ,路徑不能使用path 只能使用name,不然獲取不到傳的數據

this.$router.push({name: 'index', params: {id: 1}})

    取數據:this.$route.params.id

  2.query傳參

  

this.$router.push({path: 'good', query: {id: 2}})

  取數據:this.$route.query.id

  


免責聲明!

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



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