vue里的router跟 route

1.this.$ router

this.$ router 访问路由器 ;
this.$router 是一个全局的路由器对象,包含了很多属性和对象(比如 history 对象),任何页面都可以调用其 push(), replace(), go() ,resolve()等方法。

  1. this.$ router.resolve。
    vue 中新窗口打开vue页面 (this.$router.resolve)
  outsideLink () {
		    let {href}= this.$router.resolve({
		    path: "/newLinkPage",  
		  });
		  window.open(href, '_blank');
		}

2.this.$ router.go(n),
该方法采用一个整数作为参数,表示在历史堆栈中前进或后退多少步,类似window.history.go(n)。 this.$ router.go(1)前进一步
this.$ router.go(-1)后退一步

3.this.$ router.push()

// 字符串
this.$ router.push('home')
// 命名的路由
router.push({ name: 'user', params: { userId: 123 }})
// 带查询参数,变成/backend/order?selected=2
this.$router.push({path: '/backend/order', query: {selected: "2"}});
this.$router.push同时中同时有path跟name 的时候生效哪个变量?面试的时候遇到过这种问题。在项目中用不上。记得答案好像是生效path

2.this.$ route
this.$ route 访问当前路由 ;
this.$ route 表示当前路由对象,每一个路由都会有一个 route 对象,是一个局部的对象,可以获取对应的 name, path, params, query 等属性。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值