当前位置: 首页 > news >正文

欢迎访问陕西省交通建设集团公司网站家具网站asp

欢迎访问陕西省交通建设集团公司网站,家具网站asp,网站推广的技能,做网站工资高不高一、 背景 一个项目为vue2#xff0c;一个项目为vue3#xff0c;两个不同的项目实现iframe嵌入#xff0c;并实现通信 二、方案 iframe跨域时#xff0c;iframe组件之间常用的通信#xff0c;主要是H5的possmessage方法 三、案例代码 父页面-vue2#xff08;端口号为…一、 背景 一个项目为vue2一个项目为vue3两个不同的项目实现iframe嵌入并实现通信 二、方案 iframe跨域时iframe组件之间常用的通信主要是H5的possmessage方法 三、案例代码 父页面-vue2端口号为127.0.0.1:8080 templatedivdiv classcontaineriframerefiframeIdidiframeIdsrchttp://127.0.0.1:8081frameborder0border0hspace0vspace0scrollingyesheight100%width100%/iframe/div/div /template script langts import { Vue, Component } from vue-property-decorator;Component({components: {}, }) export default class FeatureService extends Vue {// 定义一个方法用于发送消息到iframeprivate postMessageToIframe() {// 设置延时确保iframe已经加载完成setTimeout(() {// 定义要发送的数据const iframeInfo { isIframeParent: true };// 定义目标源const targetOrigin http://127.0.0.1:8081;// 获取iframe引用const iframe this.$refs.iframeId;// 向iframe发送消息iframe.contentWindow.postMessage(JSON.stringify(iframeInfo),targetOrigin);}, 500);}private mounted() {// 在组件挂载后发送消息到iframethis.postMessageToIframe();window.addEventListener(message, this.handleMessage, false);}private handleMessage(event: MessageEvent) {// 通过origin对消息进行过滤避免遭到XSS攻击if (event.origin http://127.0.0.1:8081) {console.log(子页面传输过来参数, event.data);}} } /script style langless scoped .container {width: 100%;margin-top: -40px;height: 100vh;overflow: hidden;#iframeId {width: 100%;display: block;} } /style 子页面-vue3 (端口号为127.0.0.1:8081) templatediv!-- 顶部导航 --TopMenu v-if!iframeParentInfo.isIframeParent /div classdemo-sidebar-container demo-full-width!-- 侧边栏 --SiderBar v-if!iframeParentInfo.isIframeParent /!-- 内容容器 --ContentBox //div/div /template script setup langts import { onMounted, ref } from vueconst iframeParentInfo ref({})const messageHandler (e) {// 通过origin对消息进行过滤避免遭到XSS攻击if (e.origin ! http://127.0.0.1:8080) returnif (typeof e.data string) {parseData(e.data)} }const parseData (data) {try {iframeParentInfo.value JSON.parse(data)console.log(父页面传输过来参数, data)} catch (error) {console.error(解析JSON出错, error)iframeParentInfo.value {}} }onMounted(() {// 获取 父向 子(iframe) 传递的信息window.addEventListener(message, messageHandler)// 子(iframe)向父传递信息window.parent.postMessage(Hello Parent!, *) }) /script四、案例效果
http://www.dnsts.com.cn/news/7984.html

相关文章:

  • 兰甘肃网站建设clouder认证考试网站建设
  • 一个新的网站怎么做优化一家专业做导购的网站
  • php 电子商务网站建设做网站美工工资多少
  • 佛山专业网站设计公司wordpress做简单的商城
  • php网站模块修改绍兴网站专业制作
  • 北京网站手机站建设公司电话宁波建设集团几个分公司
  • 分析竞争对手网站建设摩托车官网中国
  • 360建设网站免费做黑彩票的网站赚钱吗
  • 福田网站建设公司乐云seo评价一个网站设计的好坏
  • 成都建立网站的公司专业做网站的顺德公司
  • 网站维护预算海口网格员
  • 云服务器上建网站网站建设 英语翻译
  • 网站可以做库存吗业务代刷平台网站怎么做
  • 商丘做网站汉狮网络linux wordpress安装
  • 汉川做网站wordpress pdf 打印
  • 自学网站查分数iis7配置asp.net网站
  • 建设银行打印回单网站平面设计师资格证怎么考
  • 天都城网站建设如何建平台网站
  • 免费的企业网站模板jwplayer wordpress
  • 网站设计要多少钱优化营商环境调度
  • 海南省建设培训与执业资格注册中心网站wordpress设置访问密码
  • 百度网站建设产品泰州高端网站建设如何收费
  • 如何免费创建自己的小程序广州网站优化流程
  • 电信ip做的网站移动不能访问怎么在360上做推广
  • 昆山周市建设局网站郑州艾特网站建设公司
  • 采集网站会员wordpress表前缀
  • 网站建设要什么软件长春网站建设电话咨询
  • 网站正在建设中换句话表达建个人网站怎么赚钱吗
  • 哪个网站建站比较好网站建设费是什么意思
  • 摄影网站开发的背景蛋糕店网站设计模板