vue项目通过url链接引入其他系统页面_vue项目嵌入别的系统,腾讯字节阿里小米京东大厂Offer拿到手软

47 阅读1分钟
<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(); // 自适应高宽度
    };
    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.引入项目的后台拦截代码

@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

最后:

总结来说,面试成功=基础知识+项目经验+表达技巧+运气。我们无法控制运气,但是我们可以在别的地方花更多时间,每个环节都提前做好准备。

面试一方面是为了找到工作,升职加薪,另一方面也是对于自我能力的考察。能够面试成功不仅仅是来自面试前的临时抱佛脚,更重要的是在平时学习和工作中不断积累和坚持,把每个知识点、每一次项目开发、每次遇到的难点知识,做好积累,实践和总结。

开源分享:docs.qq.com/doc/DSmRnRG…