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 记录。

 

猜你喜欢

转载自www.cnblogs.com/Allisson/p/10253284.html
今日推荐