router.resolve:返回一个路由地址的规范化版本。同时包含一个包含任何现有 base 的 href 属性。默认情况下,用于 router.currentRoute 的 currentLocation 应该在特别高阶的用例下才会被覆写。
打开新标签页方法
const openNewTab = ()=> {
// 打开新标签
let routeData = router.resolve(({
path: '/testPage', // path 要跳转的路由地址
// query 要传递的参数
query: {
title: this.title,
id: this.id,
type: this.type,
date: this.date,
}
}))
window.open(routeData.href,'_blank')
}
打开浏览器新窗口方法
const openNewWindow = () => {
// 打开新窗口
let left = (window.screen.width / 2 - 180) / 2 // 新窗口居中
let width = window.screen.width / 2 + 180 // 新窗口的宽度
// 新窗口要设置的参数
let params = `height=${window.screen.height},width=${width},top=0,left=${left},toolbar=no,menubar=no,scrollbars=no,resizable=yes,location=yes,status=no`
window.open(
`/testPage/{参数}`,
'_blank',
params
)
}