触发事件请求接口根据条件去判断在进行路由跳转:
- ? <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');
-
然后在回调函数中:
(改良版)
- ? <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
- ?? ? ?})
- ?}
到此这篇关于vue 路由跳转打开新窗口被浏览器拦截问题处理的文章就介绍到这了,更多相关vue 路由跳转内容请搜索w3xue以前的文章或继续浏览下面的相关文章希望大家以后多多支持w3xue!