vue-router 路由跳转

一、this.$router.push

不带参数跳转

        this.$router.push({name:'home'})

        this.$router.push({path:'/home'})

携带参数跳转

1.使用query传参,使用this.$route.query.id接受参数

        this.$router.push({name:'home',query: {id:'1'}})

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

2.使用params传参,路径只能使用name,使用this.$route.params.id接受参数

        this.$router.push({name:'home',params: {id:'1'}})

this.$router.push会向history中添加新的记录,可以使用this.$router.go(-1)回到上一个页面;在使用query传参时,参数会暴露在地址栏中,页面会保留参数可以刷新,使用params传参时,参数不会显示在地址栏中,但只有首次进入参数才能拿到,刷新后参数丢失,想要保留参数需要在路由地址中配置 path: "/home/:id"

二、this.$router.replace

this.$router.replace使用方式与this.$router.push基本一致,只是this.$router.replace不会在history中添加记录,而是替换掉history的记录,无法通过浏览器的返回功能回到上一个页面,一般用来在登出系统时使用

三、this.$router.go(n)

向前或向后跳转n个页面,n可以为正整数或负整数,一般用this.$router.go(-1)来返回上一个页面

四、this.$router.resolve

用来在浏览器新标签页打开页面,传参方式与push一致

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值