vue項(xiàng)目如何通過(guò)url鏈接引入其他系統(tǒng)頁(yè)面
vue通過(guò)url鏈接引入其他系統(tǒng)頁(yè)面
1.正常配置菜單
在vue頁(yè)面使用iframe進(jìn)行嵌套加載其它系統(tǒng)的頁(yè)面,已加載百度為例
<template>
<div id="app">
<iframe
style="border:none"
:width="searchTableWidth"
:height="searchTableHeight"
v-bind:src="reportUrl"
></iframe>
</div>
</template>
<script>
import Vue from 'vue'
export default {
methods: {
widthHeight() {
this.searchTableHeight = window.innerHeight -180;
this.searchTableWidth = window.innerWidth - 230
},
},
data() {
return {
reportUrl: 'https://www.baidu.com/',
searchTableHeight: 0,
searchTableWidth: 0
}
},
mounted() {
window.onresize = () => {
this.widthHeight(); // 自適應(yīng)高寬度
};
this.$nextTick(function () {
this.widthHeight();
});
},
created() {
// 從路由里動(dòng)態(tài)獲取 url地址 具體地址看libs下util.js里的 backendMenuToRoute 方法
this.reportUrl = 'https://www.baidu.com/'
},
watch: {
'$route': function () {
// 監(jiān)聽(tīng)路由變化
this.reportUrl = 'https://www.baidu.com/'
}
}
}
</script>效果圖:

2.加載引入系統(tǒng)可能會(huì)出現(xiàn)攔截
xxx 拒絕了我們的連接請(qǐng)求。
前端頁(yè)面Refused to display 'xxx' in a frame because it set 'X-Frame-Options' to 'sameorigin',對(duì)于這個(gè)問(wèn)題我們需要在引入的項(xiàng)目中進(jìn)行攔截處理,引入項(xiàng)目中response.addHeader("x-frame-options","SAMEORIGIN")需要改寫(xiě)為response.addHeader("x-frame-options","ALLOW-FROM http://127.0.0.1:項(xiàng)目端口/");對(duì)訪問(wèn)方式進(jìn)行允許iframe不同域名之間進(jìn)行調(diào)動(dòng)

3.引入項(xiàng)目的后臺(tái)攔截代碼
@Configuration
public class MvcConfig implements WebMvcConfigurer {
? ?//配置日志
? ? private static final Logger logger= LoggerFactory.getLogger(MvcConfig.class);
? ??
? ? @Autowired
? ? SystemConfig systemConfig;
? ?
? ? @Override
? ? public void addInterceptors(InterceptorRegistry registry) {
? ? ? ? registry.addInterceptor(new HandlerInterceptor() {
? ? ? ? ? ? @Override
? ? ? ? ? ? public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
? ? ? ? ? ? ? ? //設(shè)置日志級(jí)別
? ? ? ? ? ? ? ? //logger.debug("前置方法被執(zhí)行");
? ? ? ? ? ? ? ? return true;
? ? ? ? ? ? }
?
? ? ? ? ? ? @Override
? ? ? ? ? ? public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
? ? ? ? ? ? ? ? //logger.info("后置方法被執(zhí)行");
? ? ? ? ? ? ? ? //System.out.println(systemConfig.getMqiUrl());
? ? ? ? ? ? ?? ?if(null == modelAndView){
? ? ? ? ?? ??? ??? ?return;
? ? ? ? ?? ??? ?}
? ? ? ? ? ? ?? ?response.addHeader("x-frame-options","ALLOW-FROM http://127.0.0.1:8004/");
? ? ? ? ? ? ? ? modelAndView.getModelMap().addAttribute("arcgisserviceUrl", systemConfig.getArcgisserviceUrl());
? ? ? ? ? ? }
?
? ? ? ? ? ? @Override
? ? ? ? ? ? public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
? ? ? ? ? ? ? ? //logger.debug("最終方法被執(zhí)行");
? ? ? ? ? ? }
? ? ? ? });
? ? }
}vue頁(yè)面嵌套外部url
我的需求是一進(jìn)入頁(yè)面通過(guò)調(diào)接口獲取頁(yè)面的url,然后把url嵌套到當(dāng)前頁(yè)面。
<template>
<div class="page-content" id="bi-div"></div>
</template>
<script>
import reportFormApi from '@/api/reportForm'
export default {
name: 'reportComponent',
props:{
codeStr:String
},
data () {
return {
urlCode :"",
}
},
mounted: function () {
if(this.codeStr){
this.urlCode = this.codeStr;
this.getUrl();
}
},
methods: {
getUrl(){
reportFormApi.getQuickBi({url : "/postUrl/" + this.urlCode}).then(res=>{
if(res.code==0){
var frame = '<iframe frameborder="no" border="0" marginwidth="0" marginheight="0" scrolling="no" width="100%" height="100%" src="' + res.data.previewUrl + '"></iframe>';
var newNode = document.createElement('div');
newNode.innerHTML = frame;
newNode.style.height = '1200px';
var htmlBody = document.getElementById('bi-div');
htmlBody.insertBefore(newNode, htmlBody.firstChild);
}else{
this.$Message.error({
content: res.message,
duration: 2.5,
closable:true,
});
}
})
}
}
}
</script>
總結(jié)
以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
vue2+element-ui使用vue-i18n進(jìn)行國(guó)際化的多語(yǔ)言/國(guó)際化詳細(xì)教程
這篇文章主要給大家介紹了關(guān)于vue2+element-ui使用vue-i18n進(jìn)行國(guó)際化的多語(yǔ)言/國(guó)際化的相關(guān)資料,I18n是Vue.js的國(guó)際化插件,項(xiàng)目里面的中英文等多語(yǔ)言切換會(huì)使用到這個(gè)東西,需要的朋友可以參考下2023-12-12
vue3前端實(shí)現(xiàn)全屏顯示及元素垂直填滿頁(yè)面效果
這篇文章主要給大家介紹了關(guān)于vue3前端實(shí)現(xiàn)全屏顯示及元素垂直填滿頁(yè)面效果的相關(guān)資料,文中還給大家介紹了vue3實(shí)現(xiàn)某一個(gè)元素全屏之后就黑屏了的解決辦法,需要的朋友可以參考下2024-02-02
vue.js 使用axios實(shí)現(xiàn)下載功能的示例
下面小編就為大家分享一篇vue.js 使用axios實(shí)現(xiàn)下載功能的示例,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看2018-03-03
vue?navbar?tabbar導(dǎo)航條根據(jù)位置移動(dòng)實(shí)現(xiàn)定位、顏色過(guò)渡動(dòng)畫(huà)效果的代碼
這篇文章主要介紹了vue?navbar?tabbar導(dǎo)航條根據(jù)位置移動(dòng)實(shí)現(xiàn)定位、顏色過(guò)渡動(dòng)畫(huà)效果,本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2022-08-08
vue3.0 子組件如何修改父組件傳遞過(guò)來(lái)的值
這篇文章主要介紹了vue3.0 子組件如何修改父組件傳遞過(guò)來(lái)的值,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-04-04
Vue中正確使用Element-UI組件的方法實(shí)例
這篇文章主要給大家介紹了關(guān)于Vue中正確使用Element-UI組件的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2020-10-10
Vue3如何解決Element-plus不生效的問(wèn)題
這篇文章主要介紹了Vue3如何解決Element-plus不生效的問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2024-03-03

