@cqupt-hub/iframe-poster
v0.0.5
Published
智荟通云小程序通信工具库
Downloads
2
Readme
云小程序通信解决方案
安装:
npm install @cqupt-hub/iframe-poster
使用:
npm:
import { Poster } from "@cqupt-hub/iframe-poster"
通信示例:
父页面:
import { Poster } from "@cqupt-hub/iframe-poster";
let childIframe = document.getElementById("childIframeId");
child = new Poster(childIframe as HTMLIFrameElement, "childIframeId", "http://example");
child.on("ready", (data) => {
console.log("子页面已经准备就绪");
child1.post("send", { count: count1.value });
});
child.on("update", (data) => {
console.log("子页面传来了更新的消息");
});
子页面:
import { Poster } from "@cqupt-hub/iframe-poster";
let parent = new Poster();
parent.on("send", (data) => {
console.log("父页面传来了消息");
});
嵌入白名单
import { Poster } from "@cqupt-hub/iframe-poster";
//添加允许的域名
Poster.WhitelistAdd("localhost");
//移除域名
Poster.WhitelistRemove("localhost");
//开启监听
Poster.WhitelistOn();
//关闭监听
Poster.WhitelistOff();
在线演示:
https://stackblitz.com/edit/vitejs-vite-soyj5p?file=src%2Fviews%2FiframeChild2.vue