您好,登錄后才能下訂單哦!
本篇內容主要講解“vue項目怎么通過url鏈接引入其他系統頁面”,感興趣的朋友不妨來看看。本文介紹的方法操作簡單快捷,實用性強。下面就讓小編來帶大家學習“vue項目怎么通過url鏈接引入其他系統頁面”吧!
在vue頁面使用iframe進行嵌套加載其它系統的頁面,已加載百度為例
<template> <div id="app"> <iframe :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(); // 自適應高寬度 }; this.$nextTick(function () { this.widthHeight(); }); }, created() { // 從路由里動態獲取 url地址 具體地址看libs下util.js里的 backendMenuToRoute 方法 this.reportUrl = 'https://www.baidu.com/' }, watch: { '$route': function () { // 監聽路由變化 this.reportUrl = 'https://www.baidu.com/' } } } </script>
效果圖:
xxx 拒絕了我們的連接請求。
前端頁面Refused to display 'xxx' in a frame because it set 'X-Frame-Options' to 'sameorigin',對于這個問題我們需要在引入的項目中進行攔截處理,引入項目中response.addHeader("x-frame-options","SAMEORIGIN")需要改寫為response.addHeader("x-frame-options","ALLOW-FROM http://127.0.0.1:項目端口/");對訪問方式進行允許iframe不同域名之間進行調動
@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 { //設置日志級別 //logger.debug("前置方法被執行"); return true; } @Override public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception { //logger.info("后置方法被執行"); //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("最終方法被執行"); } }); } }
我的需求是一進入頁面通過調接口獲取頁面的url,然后把url嵌套到當前頁面。
<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>
到此,相信大家對“vue項目怎么通過url鏈接引入其他系統頁面”有了更深的了解,不妨來實際操作一番吧!這里是億速云網站,更多相關內容可以進入相關頻道進行查詢,關注我們,繼續學習!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。