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

vue配置iframe父级窗口通信

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

在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父级窗口通信” 的相关文章

PHP分页函数仿Google分页

/**  * 分页函数  * @param int $total    总页数  * @param int $pagesize 每页几条 &n...

php获取从百度搜索进入网站的关键词

<?php    function search_word_from() {     $referer = isset($_SERVER['HTTP_REFERER'])?...

php 获取客户端的ip、地理信息、浏览器信息、本地真实ip

<?php  // 作用取得客户端的ip、地理信息、浏览器http://blog.qita.in  class get_gust_info {        ////获得访客浏...

利用ctrl+v实现粘贴截图完成上传功能

<?php header("Access-Control-Allow-Origin:*"); $url  = 'http://'.$_SERVER['HTTP_HOST']; $file =&nb...

thinkphp获取URL参数

一般情况下URL中的参数就是通过GET方法获取,但是由于PATHINFO的特 殊性,URL地址最终需要被解析才能转换成GET参数,ThinkPHP对URL是按照一定的规则进行解析的,除非你使用了URL路由规则,如果你对 URL做了特别的定制,但是又不想使用URL路由,那么可以使用框架提供的URL...

jQuery编程的最佳实践

加载jQuery1.坚持使用CDN来加载jQuery,这种别人服务器免费帮你托管文件的便宜干嘛不占呢。点击查看使用CDN的好处,点此查看一些主流的jQuery CDN地址。<script type="text/javascript" src="...

发表评论

访客

看不清,换一张

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