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

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