22-vue之使用编程式导航

  // 使用JS的形式进行路由导航

      // 注意: 一定要区分 this.$route 和 this.$router 这两个对象,
      // 其中: this.$route 是路由【参数对象】,所有路由中的参数, params, query 都属于它
      // 其中: this.$router 是一个路由【导航对象】,用它 可以方便的 使用 JS 代码,实现路由的 前进、后退、 跳转到新的 URL 地址

      console.log(this);
      // 1. 最简单的
      // this.$router.push("/home/goodsinfo/" + id);
      // 2. 传递对象
      // this.$router.push({ path: "/home/goodsinfo/" + id });
      // 3. 传递命名的路由(这里的name是注册到router中的path定义的name)
      this.$router.push({ name: "goodsinfo", params: { id } });

  

posted @ 2020-12-16 15:04  丿少女梦丶  阅读(91)  评论(0编辑  收藏  举报