开发的时候,遇到一个需求
1.新窗口打开路由
2.路由传参
新窗口打开路由的实现
使用resolve
路由传参
使用query
代码如下
let condition = this.condition
let href = this.$router.resolve({
name: 'detail',
query: {
id: condition
}
})
console.log(href)
window.open(href.href, '_blank')
代码解析
name:'detail'
在路由router文件夹中有定义
export default new Router({
routes: [
{
path: '/index',
name: 'HelloWorld',
component: index,
children: [
{
path: '/',
component: monitor
},
{
path: 'detail',
name: 'detail',
component: detail
}
]
}
]
})
再看跳转的时候,使用的是window.open
一开始我直接使用了href,发现跳转过去路由不正确,打印出来看另有玄机
href是一个对象,里面包含了很多东西,此次没有详细了解,使用了里面的href,于是新窗口打开路由实现了。