时间:2023-01-25 10:07:16 | 栏目:vue | 点击:次
触发事件请求接口根据条件去判断在进行路由跳转:
<a @click="getGetMyPortfolioById(scope.row) ">查看</a>
getGetMyPortfolioById(vals) {
getMyPortfolioById({
}).then(response = >{
const routerdata = this.$router.resolve({
name: '组合分析以及组合持仓',
params: { managerId: vals.fundCode }
})
const newhref = routerdata.href + '?managerId=' + vals.fundCode
window.open(newhref, '_blank')
})
}
当我们用以上方法时候,是触发事件请求接口根据条件去判断在进行路由跳转,这个时候就会遇到浏览器被拦截的问题
在接口请求的回调函数中 需要使用window.open()打开新页面,但是等接口请求成功之后,window.open()打开新页面总是被浏览器拦截,原因大概是,放在请求回调函数中的操作,被浏览器认为不是用户主动触发的事件,并且延迟1000ms ,被认为有可能是广告,于是被拦截
解决的方法:
在接口请求之前先打开一个空的页面:
let tempPage=window.open('' ", _blank');
然后在回调函数中:
tempPage.location=url;
(改良版)
<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
})
}