router和route的理解


$router : 是路由操作對象,只寫對象

$route : 路由信息對象,只讀對象

如果要在刷新頁面的時候通過路由的信息來操作數據,可以在created下
使用this.$route 這個的屬性

 

this.$route 存着一些與路由相關的信息
常用的:
parmas 預設的變量
path 當前的路由的路徑
query 查詢信息 ?號
hash hash信息 #號
 
操作 路由跳轉
this.$router.push({
      name:'hello',
      params:{
          name:'word',
          age:'11'
     }
})

讀取 路由參數接收
this.name = this.$route.params.name;
this.age = this.$route.params.age;
 
 

 

router.go(n)
這個方法的參數是一個整數,意思是在 history 記錄中向前或者后退多少步,類似 window.history.go(n)

router.push(location)
想要導航到不同的 URL,則使用 router.push 方法。這個方法會向 history 棧添加一個新的記錄,所以,當用戶點擊瀏覽器后退按鈕時,則回到之前的 URL。

router.replace(location)
跟 router.push 很像,唯一的不同就是,它不會向 history 添加新記錄,而是跟它的方法名一樣 —— 替換掉當前的 history 記錄。

 


免責聲明!

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



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