vue 路由跳轉開啟新視窗(被瀏覽器攔截)
阿新 • • 發佈:2018-11-16
今天做了一個功能是點選按鈕路由跳轉開啟新的視窗頁面
- 第一種方法
<router-link target="_blank" :to="{path:'/FundManger/FundProductMoney',
query:{managerId:fundcode}}></router-link>"
- 第二種方法
<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;