vue 跳转页面打开浏览器新窗口或者打开新标签

打开浏览器新窗口方法:

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/${this.title}/${this.id}/${this.type}/${this.date}`,'_blank',params)},
    
   // 注意:路由地址的 path 必须配置成以下这样,有几个参数就配置几个参数
   // path : '/testPage/:title/:id/:type/:date'
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.

打开新标签页方法:

 openNewTab () {
    // 打开新标签
    let routeData = this.$router.resolve(({
    path: '/testPage', // path 要跳转的路由地址
    // query 要传递的参数
    query: { 
       title: this.title,
       id: this.id,
       type: this.type,
       date: this.date,
     }
    }))
    window.open(routeData.href,'_blank')
 },
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.