open-index/open-npm huggingface dataset:
npm package: @iqidaosdk/iframe
Description: common use js iframe lib
Author: huzhengtaoalex
Latest version: 1.0.20

# @iqidaosdk/iframe

基于iframe通道，在不限制技术框架的基础上，实现通用模块与不同项目的数据传输和交互，iframe也输入微前端的一种实现方案

- iframe通道原理
![通道](./images/framework.png)

- @iqidaosdk/iframe 扩展
![扩展](./images/sdk.png)

## Install

npm install @iqidaosdk/iframe --save

yarn add @iqidaosdk/iframe --save

## Code Examples

### 基础调用

```javascript
import iqdSdkIframe from '@iqidaosdk/iframe'

 if(window.location.hostname !== 'localhost'){
    const IqdSdkIframe = iqdSdkIframe.init({
      sdkModule:'pay',
      env:'dev',
      role:'parent',
      loadUrl:'https://dev-payment.iqidao.com/web/basic-component-sevice/pay?token=' + localStorage.getItem('token'),
      wrap:'#pay-iframe',
      targetOrigin:'https://dev-payment.iqidao.com',
    })
  }
```

### 订阅和发送消息
```javascript
import iqdSdkIframe from '@iqidaosdk/iframe'

 if(window.location.hostname !== 'localhost'){
    const IqdSdkIframe = iqdSdkIframe.init({
      sdkModule:'pay',
      env:'dev',
      role:'parent',
      loadUrl:'https://dev-payment.iqidao.com/web/basic-component-sevice/pay?token=' + localStorage.getItem('token'),
      wrap:'#pay-iframe',
      targetOrigin:'https://dev-payment.iqidao.com',
    })
    // 调用微服务的事件，type=‘event’
    IqdSdkIframe.channel.postMessage('parent',{
      type:'event',
      message: {
        order_id:1
      },
      eventName:'pay'
    })
    
  }
  // 监听微服务消息
     IqdSdkIframe.channel.subscribe('child', (data,message,event) => {
      console.log(data)
      return data
    })
  // 销毁iframe模块
     IqdSdkIframe.destroy()
```


## API Documentation


| Param                | Type                | Description                                 | eg|
| ---------------------| ------------------- | ------------------------------------------- |------------------- | 
| sdkModule           | <code>string</code> | 调用微服务对应的模块 | pay
| env           | <code>string</code> | 对应的开发环境 | local,dev,test,prod
| role           | <code>string</code> | 用户身份 | parent，child
| loadUrl    | <code>string</code> | 对应打开的iframe地址| https://dev-payment.iqidao.com/web/basic-component-sevice/pay?token=' + localStorage.getItem('token')
| wrap           | <code>string</code> | iframe放置的元素| #pay-iframe
| targetOrigin | <code>string</code> | | |
| token | <code>string</code> | | localStorage.getItem('token')|