一般的 vue-router 跳转,都是在当前页面切换 路由地址,实质就是 router-view中的内容变动, 如果想要打开新的窗口怎么办?
假设当前的路由地址是 http://localhost:8001#/news 点击详情,需要跳转到 http://localhost:8001#/detail?pid=12 的页面
news.vue
<template>
<button @click='go(12)'>跳转</button>
</template>
<script>
export default {
methods: {
go(id) {
const router = this.$router.resolve({
path: '/detail',
query: { pid: id }
})
window.open(router.href, '_blank')
}
}
}
</script>
http://localhost:8001#/detail?pid=12 还是正常的解析 参数即可
detail.vue
...省略
<script>
export default {
created() {
const { pid } = this.$route.query
}
}
</script>
还有, 注意,自己的路由表一定要是添加了 detail.vue, 还有,有的公司是配置了跟权限相关的,也要检查一下