关于vue2路由跳转问题记录

1. vue 路由间跳转和新开窗口的方式(query, params)

路由间跳转配置:
query方式:参数会在url中显示
this.$router.push({
path: '路由地址',
query: {
msg: 'hello world'
}
})

params方式:传参数据不会在导航栏中显示,需要配合路由的name属性使用。
this.$router.push({
name: '',
params: {
msg: 'hello world'
}
})

新开页面,需要使用resolve配置,如:
const { href } = this.$router.resolve({
path: '/path',
query: {
msg: 'hello'
}
})
window.open(href, '_blank')
注意一下:如果是使用这种方式,不可以使用params进行传参,因为获取不到,传不过去。query是可以正常传参的。

 

posted on 2023-06-16 15:35  有匪  阅读(148)  评论(0编辑  收藏  举报

导航