vue项目怎么通过url链接引入其他系统页面

免费教程   2024年05月09日 22:24  

本篇内容主要讲解“vue项目怎么通过url链接引入其他系统页面”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“vue项目怎么通过url链接引入其他系统页面”吧!

vue通过url链接引入其他系统页面1.正常配置菜单

在vue页面使用iframe进行嵌套加载其它系统的页面,已加载百度为例

<template><divid="app"><iframe:width="searchTableWidth":height="searchTableHeight"v-bind:src="reportUrl"></iframe></div></template><script>importVuefrom''exportdefault{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>

效果图:

2.加载引入系统可能会出现拦截

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不同域名之间进行调动

3.引入项目的后台拦截代码@ConfigurationpublicclassMvcConfigimplementsWebMvcConfigurer{//配置日志privatestaticfinalLoggerlogger=LoggerFactory.getLogger(MvcConfig.class);@AutowiredSystemConfigsystemConfig;@OverridepublicvoidaddInterceptors(InterceptorRegistryregistry){registry.addInterceptor(newHandlerInterceptor(){@OverridepublicbooleanpreHandle(HttpServletRequestrequest,HttpServletResponseresponse,Objecthandler)throwsException{//设置日志级别//logger.debug("前置方法被执行");returntrue;}@OverridepublicvoidpostHandle(HttpServletRequestrequest,HttpServletResponseresponse,Objecthandler,ModelAndViewmodelAndView)throwsException{//logger.info("后置方法被执行");//System.out.println(systemConfig.getMqiUrl());if(null==modelAndView){return;}response.addHeader("x-frame-options","ALLOW-FROMhttp://127.0.0.1:8004/");modelAndView.getModelMap().addAttribute("arcgisserviceUrl",systemConfig.getArcgisserviceUrl());}@OverridepublicvoidafterCompletion(HttpServletRequestrequest,HttpServletResponseresponse,Objecthandler,Exceptionex)throwsException{//logger.debug("最终方法被执行");}});}}vue页面嵌套外部url

我的需求是一进入页面通过调接口获取页面的url,然后把url嵌套到当前页面。

<template><divclass="page-content"id="bi-div"></div></template><script>importreportFormApifrom'@/api/reportForm'exportdefault{name:'reportComponent',props:{codeStr:String},data(){return{urlCode:"",}},mounted:function(){if(this.codeStr){this.urlCode=this.codeStr;this.getUrl();}},methods:{getUrl(){reportFormApi.getQuickBi({:"/postUrl/"+this.urlCode}).then(res=>{if(res.code==0){varframe='<iframeframeborder="no"border="0"marginwidth="0"marginheight="0"scrolling="no"width="100%"height="100%"src="'+res.data.previewUrl+'"></iframe>';varnewNode=document.createElement('div');newNode.innerHTML=frame;newNode.style.height='1200px';varhtmlBody=document.getElementById('bi-div');htmlBody.insertBefore(newNode,htmlBody.firstChild);}else{this.$Message.error({content:res.message,duration:2.5,closable:true,});}})}}}</script>

到此,相信大家对“vue项目怎么通过url链接引入其他系统页面”有了更深的了解,不妨来实际操作一番吧!这里是网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!

域名注册
购买VPS主机

您或许对下面这些文章有兴趣:                    本月吐槽辛苦排行榜

看贴要回贴有N种理由!看帖不回贴的后果你懂得的!


评论内容 (*必填):
(Ctrl + Enter提交)   

部落快速搜索栏

各类专题梳理

网站导航栏

X
返回顶部