vue 路由跳转打开新窗口(被浏览器拦截)

今天做了一个功能是点击按钮路由跳转打开新的窗口页面

  1. 第一种方法
<router-link target="_blank" :to="{path:'/FundManger/FundProductMoney',
query:{managerId:fundcode}}></router-link>"
  1. 第二种方法
  <a @click="getGetMyPortfolioById(scope.row) ">查看</a>

  getGetMyPortfolioById(vals) {
      const tempPage = window.open('', '_blank')
	  getMyPortfolioById({}).then(response = >{
			 const routerdata = this.$router.resolve({
        	 name: '组合分析以及组合持仓',
         	 	params: {
               		managerId: vals.fundCode
         		}
      		 })
     		const newhref = routerdata.href + '?managerId=' + vals.fundCode
     		tempPage.location = newhref
	  })
 }
      

当我们用到第二种方法时候,是触发事件请求接口根据条件去判断在进行路由跳转,这个时候就会遇到浏览器被拦截的问题
在接口请求的回调函数中 需要使用window.open()打开新页面,但是等接口请求成功之后,window.open()打开新页面总是被浏览器拦截,原因大概是,放在请求回调函数中的操作,被浏览器认为不是用户主动触发的事件,并且延迟1000ms ,被认为有可能是广告,于是被拦截

解决的方法:

在接口请求之前先打开一个空的页面
let tempPage=window.open(’’ ", _blank’);
然后在回调函数中,
tempPage.location=url;

猜你喜欢

转载自blog.csdn.net/weixin_43609391/article/details/83791154
今日推荐