vue跳转页面时打开新的页面

Vue中,你可以使用router-link组件或编程式导航来实现页面跳转。如果你想在跳转时打开一个新的页面(即新标签页或新窗口),你可以使用target="_blank"属性或编程式导航的replace方法。

下面是两种方法的示例:

  1. 使用router-link组件:

vue
<template>  
  <router-link :to="url" target="_blank">打开新页面</router-link>  
</template>  
  
<script>  
export default {  
  data() {  
    return {  
      url: '/new-page' // 目标页面的路径  
    };  
  }  
};  
</script>

2.使用window.open方法:
你可以使用JavaScript的window.open方法来打开一个新的标签页,并传递所需的参数

window.open('/ticket/historyPrice?name=' + obj.H航司名 + '&fn=' + obj.H航班号 + '&from=' + obj.C出发机场 + '&to=' + obj.D到达机场 + '&date=' + obj.C出发时间_Date, '_blank');

//例子1:
//如果你的目标页面/ticket/historyPrice在当前组件的目录下,你可以这样写路径:
window.open('./ticket/historyPrice?name=' + obj.H航司名 + '&fn=' + obj.H航班号 + '&from=' + obj.C出发机场 + '&to=' + obj.D到达机场 + '&date=' + obj.C出发时间_Date, '_blank');
//如果你希望在项目的根目录下打开新的页面,你可以这样写路径:
window.open('/ticket/historyPrice?name=' + obj.H航司名 + '&fn=' + obj.H航班号 + '&from=' + obj.C出发机场 + '&to=' + obj.D到达机场 + '&date=' + obj.C出发时间_Date, '_blank');


请注意,在使用window.open方法时,需要将参数拼接到URL中,并通过_blank参数指定在新标签页中打开页面。


export default {  
  mounted() {  
    const name = this.$route.query.name;  
    const fn = this.$route.query.fn;  
    const from = this.$route.query.from;  
    const to = this.$route.query.to;  
    const date = this.$route.query.date;  
  
    // 在这里使用接收到的参数进行相应的操作  
  }  
}
  • 14
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值