vue?路由跳轉打開新窗口被瀏覽器攔截問題處理
觸發(fā)事件請求接口根據條件去判斷在進行路由跳轉:
? <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')?
? ? })
?}?當我們用以上方法時候,是觸發(fā)事件請求接口根據條件去判斷在進行路由跳轉,這個時候就會遇到瀏覽器被攔截的問題
在接口請求的回調函數中 需要使用window.open()打開新頁面,但是等接口請求成功之后,window.open()打開新頁面總是被瀏覽器攔截,原因大概是,放在請求回調函數中的操作,被瀏覽器認為不是用戶主動觸發(fā)的事件,并且延遲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
?? ? ?})
?}到此這篇關于vue 路由跳轉打開新窗口被瀏覽器攔截問題處理的文章就介紹到這了,更多相關vue 路由跳轉內容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!
相關文章
vue實現錄音功能js-audio-recorder帶波浪圖效果的示例
這篇文章主要介紹了vue實現錄音功能js-audio-recorder帶波浪圖效果,本文通過實例代碼給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下2022-08-08
mui-player自定義底部導航在vue項目中顯示不出來的解決
這篇文章主要介紹了mui-player自定義底部導航在vue項目中顯示不出來的解決方案,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2022-12-12
Vue中圖片上傳組件封裝-antd的a-upload二次封裝的實例
這篇文章主要介紹了Vue中圖片上傳組件封裝-antd的a-upload二次封裝的實例,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2022-09-09

