router和route的理解
阿新 • • 發佈:2019-01-11
$router : 是路由操作物件,只寫物件
$route : 路由資訊物件,只讀物件
如果要在重新整理頁面的時候通過路由的資訊來操作資料,可以在created下 使用this.$route 這個的屬性this.$route 存著一些與路由相關的資訊 常用的: parmas 預設的變數 path 當前的路由的路徑 query 查詢資訊 ?號 hash hash資訊 #號
操作 路由跳轉 this.$router.push({ name:'hello', params:{ name:'word', age:'11' } })
router.go(n) 這個方法的引數是一個整數,意思是在 history 記錄中向前或者後退多少步,類似 window.history.go(n)
router.push(location) 想要導航到不同的 URL,則使用 router.push 方法。這個方法會向 history 棧新增一個新的記錄,所以,當用戶點選瀏覽器後退按鈕時,則回到之前的 URL。
router.replace(location) 跟 router.push 很像,唯一的不同就是,它不會向 history 新增新記錄,而是跟它的方法名一樣 —— 替換掉當前的 history 記錄。