$router和$route的区别

$router是一个VueRouter的实例 可以导航到不同的路由里

$route是$router跳转到的当前一个对象,里面包含该对象的path、query、name 、params

用法 : this.$router.push()  跳转到指定的url 会向history栈添加一个记录 点击后退会返回上一页面

1、this.$router.push({path:'/detail',query:{}})    this.$router.push('/detail')

使用当前的query  this.$route.query

2、this.$router.push({name:'detail',params:{}})

使用当前的params this.$route.params

this.$router.replace() 跳转到指定的url 不会向history栈添加一个记录 点击后退会返回上上一页面 上一个记录是不存在的

this.$router.go(n) 向前或向后跳转多少个页面(类似于 window.history.go())

猜你喜欢

转载自blog.csdn.net/qq_39039128/article/details/87165013