$router和$route的区别

学习分享1年前 (2023)更新 bestcyt
124 0 0
  • $router

$router是编程式导航,this.$router.push(‘要跳转的路径名’),还有this.$router.go(-1)返回上一页面。

  • $route

vue2.0里页面参数是 this.$route.query或者 this.$route.params 接收router-link传的参数,
$route为当前router跳转对象里面可以获取name、path、query、params等。

// 存放商品 id,数量的对象
const payload = {
      goodsId:this.$route.params.goodsId,
      count:this.goodsCount
 }

 

© 版权声明

相关文章