Laravel  
laravel
文档
数据库
架构
入门
php技术
    
Laravelphp
laravel / php / java / vue / mysql / linux / python / javascript / html / css / c++ / c#

vue路由跳转打开新窗口

作者:殘沫灕汐   发布日期:2025-07-21   浏览:34

// 使用 Vue Router 进行路由跳转并打开新窗口的示例代码

// 假设你已经在项目中配置好了 Vue Router,并且有如下路由配置:
// {
//   path: '/target',
//   name: 'Target',
//   component: TargetComponent
// }

// 在组件中使用以下代码进行路由跳转并打开新窗口:

methods: {
  openNewWindow() {
    // 获取目标路由的完整路径,包括 query 参数等
    const routePath = this.$router.resolve({ name: 'Target', query: { id: 123 } });

    // 使用 window.open 打开新窗口
    window.open(routePath.href, '_blank');

    // 如果需要在当前页面也进行跳转,可以添加以下代码
    // this.$router.push({ name: 'Target', query: { id: 123 } });
  }
}

解释说明:

  1. this.$router.resolve:用于解析路由对象为实际的 URL。它返回一个包含 href 属性的对象,href 是完整的 URL 字符串。
  2. window.open:用于在新窗口中打开指定的 URL。第二个参数 _blank 表示在新标签页中打开。
  3. this.$router.push(可选):如果你还想在当前页面进行跳转,可以使用 push 方法。

这样,点击按钮或触发该方法时,会在新窗口中打开目标路由,并且可以根据需要决定是否同时在当前页面跳转。

上一篇:vue style 动态

下一篇:vue项目运行命令

大家都在看

vue.config.js configu

node.js vue

vue 图表组件

vue3watch监听多个变量

vue查看版本

vue3 reactive对象重新赋值

vue等待几秒

vue3 setup computed

vue screenfull

vue json.stringify

Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3

Laravel 中文站