amis App多页应用模式下,菜单切换后,iframe的onEvent 事件反复执行

zqdjd7g9  于 2023-02-04  发布在  其他
关注(0)|答案(1)|浏览(630)
描述问题:

使用 2.6.0 版本的 jssdk,在源码 https://github.com/aisuda/amis-admin 的基础上,添加一个菜单,用于测试 iframe 组件的 onEvent 事件。

在使用的过程中,发现从 iframe 的菜单项切换到其他的菜单,再重新切换回来时,组件的 onEvent事件会反复触发,并且每切换一次,触发的事件会多累计一次。

截图或视频:

default.mp4

视频打开是空白的,不知道是不是在审核中的原因,故将视频转为 gif,辛苦大佬看一下。

如何复现(请务必完整填写下面内容):
  1. 你是如何使用 amis 的?
    sdk
  2. amis 版本是什么?请先在最新 beta 版本测试问题是否存在

2.6.0

  1. 粘贴有问题的完整 amis schema 代码:

上述开源项目中,site.json 中添加一个菜单:

iframe.json 源码

{
  "type": "page",
  "body": {
    "type": "iframe",
    "src": "../pages/iframe.html",
    "onEvent": {
      "tttt": {
        "actions": [
          {
            "actionType": "toast",
            "args": {
              "msgType": "info",
              "msg": "提示。。。。"
            }
          }
        ]
      }
    }
  }
}

iframe.html 源码

<!DOCTYPE html>
<html lang="zh">
<head>
  <meta charset="UTF-8">
  <title>Iframe 测试</title>
</head>
<body>
<div style="border: 1px solid red; width: 100%; height: 200px;">

  <button onclick="dialog()">父层弹框</button>
  <br>
  <button onclick="toast()">toast提示</button>

</div>
</body>
<script>
function dialog() {
}
function toast() {
  window.parent.postMessage({type: 'amis:tttt', data: {}}, '*');
}
</script>
</html>
  1. 操作步骤

来回切换菜单后,iframe 的 onEvent 事件会累计,整个网页重新刷新后,首次正常,后续仍然会反复执行。

afdcj2ne

afdcj2ne1#

👍 Thanks for this!
🏷 I have applied any labels matching special text in your issue.

Please review the labels and make any necessary changes.

相关问题