当前位置:首页 > 技术文档 > 正文内容

vue配置iframe父级窗口通信

admin3年前 (2023-02-07)技术文档175

在router/index.js中配置


export default new Router({
  scrollBehavior: () => ({ y: 0 }),
  routes: [
    {
      path: '/',
      name: 'index',
      component: resolve => require(['@/views/index'], resolve),
      meta: {
        keepAlive: true, // 此组件需要被缓存
        isIframe: true // 标记是否是iframe
      }
    }
  ]
})


在入口文件main.js中配置


// 判断当前路由是否需要iframe
router.beforeEach((to, from, next) => {
  if (to.meta.isIframe) {
    window.parent.postMessage({
      type: 'setIframeHeight',
      height: document.documentElement.scrollHeight
    }, '*')
  }
  next()
})


在父页面中添加


<script>
  window.addEventListener('message', function (e) {
    if (e.data.type === 'setIframeHeight') {
      document.querySelector('#iframe').height = e.data.height
    }
  })
</script>



分享到:

扫描二维码推送至手机访问。

版权声明:本文由云河空间发布,如需转载请注明出处。

本文链接:https://yuyunhe.cn/index.php/post/322.html

分享给朋友:

“vue配置iframe父级窗口通信” 的相关文章

wamp下虚拟主机的配置

1  编辑httpd.conf,查找Include conf/extra/httpd-vhosts.conf,把前面注释符号“#”删掉。 2  编辑httpd-vhosts.conf,我把WAMPServer安装在D:/wamp,所以我这里的路径是D:\wamp\Apache2\...

推荐一些国内的Jquery CDN免费服务

Jquery是个非常流行的JS前端框架,在很多网站都能看到它的身影。很多网站都喜欢采用一些Jquery CDN加速服务,这样网站加载jquery会更快。之前火端网络的一些网站都是使用Google的jquery CDN,如:http://ajax.googleapis.com/ajax/lib...

wamp虚拟主机配置

1、首先打开apache的配置文件httpd.conf,并去掉#Include conf/extra/httpd-vhosts.conf前面的#,启用虚拟主机功能2、先把localhost配置好,免得以后访问localhost出现问题,我的wamp项目根目录是D:\wamp\www。将下面信息添加到...

php二维数组转换为一维数组的几种方法

在开发过程中,我们经常需要将二维数组转为一维数组,个人总结了2种方法,分享给大家如何将下面的二维数组转为一维数组。复制代码 代码如下:$msg = array(  array(    'id'=>'45',    'name'=>'...

ThinkPHP实现多数据库连接的解决方法

这篇文章主要介绍了ThinkPHP实现多数据库连接的解决方法,需要的朋友可以参考下ThinkPHP实现连接多个数据的时候,如果数据库在同一个服务器里的话只需要这样定义模型:?123class MembersModel extends Model{protected $trueTableName =...

TP 查询缓存

<?php     function cache_data($sql){             $SqlDao&nbs...

发表评论

访客

看不清,换一张

◎欢迎参与讨论,请在这里发表您的看法和观点。