VUE this.$route 和 this.$router

在這裏插入圖片描述
this.routethis.route 和 this.router :

this.$route 是路由【參數對象】,所有路由中的參數, params, query 都屬於它。
用來獲取路由信息,包含的是路由基本信息,如fullPath等,

this.$route.matched[0].name

this.$router 是路由【導航對象】,用它 可以方便的 使用 JS 代碼,實現路由的 前進、後退、 跳轉到新的 URL 地址。
用來進行路由操作,在原型鏈(proto)中包含路由的處理方法,如跳轉push等。

this.$router.push({path:'/addNew'})
this.$router.push('/')   //跳轉到根目錄,保留歷史記錄,可以返回
this.$router.replace('/')  //跳轉到根目錄,替換掉當前歷史記錄,無法返回替換前的頁面
this.$router.back()  //返回上一個頁面
this.$router.go(1) // 1 爲向前跳轉,-1 爲返回(相當於back)

參考:https://blog.csdn.net/LzzMandy/article/details/92782553

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章