前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Vue Router 实现多种页面跳转

Vue Router 实现多种页面跳转

作者头像
明知山
发布2020-09-03 10:20:20
8290
发布2020-09-03 10:20:20
举报
文章被收录于专栏:前端开发随笔前端开发随笔

router-link

这种跳转方式类似于传统的a 标签实现跳转

 <router-link to="./shop">Go Shop</router-link>

this.$router.push

用的较多的是使用方法进行跳转然后实现页面之间的传参

<div  @click="gohome">我要去home</div>
<script>
export default {
  data() {
    return {
      id:5
    };
  },
  methods: {
    gohome() {
      this.$router.push({
        path: "/home",
        query: {
          id: this.id
        }
      });
    }
  },
};
</script>

接收参数页面 在域名就会看到域名带?id=5

<script>
export default {
  data() {
    return {};
  },
  methods:{
  },
 created(){  //生命周期里接收参数
 	this.id = this.$route.query.id, 
    console.log(this.id)   
   }
};

this.$router.replace

用法跟this.$router.push一样,但是跳转有区别。 前者跳转之后会向history栈添加一个记录,点击后退会返回到上一个页面。 后者跳转不会向history里面添加新的记录,点击返回,会跳转到上上一个页面。上一个记录是不存在的。

this.$router.go()

类似于window.history.go(n)。

    // 在浏览器记录中前进一步,等同于 history.forward()
    this.$router.go(1)
    
    // 后退一步记录,等同于 history.back()
    this.$router.go(-1)
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2019-08-12 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • router-link
  • this.$router.push
  • this.$router.replace
  • this.$router.go()
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档