1.0.20 • Published 1 year ago

@iqidaosdk/iframe v1.0.20

Weekly downloads
-
License
-
Repository
-
Last release
1 year ago

@iqidaosdk/iframe

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

  • iframe通道原理 通道

  • @iqidaosdk/iframe 扩展 扩展

Install

npm install @iqidaosdk/iframe --save

yarn add @iqidaosdk/iframe --save

Code Examples

基础调用

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',
    })
  }

订阅和发送消息

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

ParamTypeDescriptioneg
sdkModulestring调用微服务对应的模块pay
envstring对应的开发环境local,dev,test,prod
rolestring用户身份parent,child
loadUrlstring对应打开的iframe地址https://dev-payment.iqidao.com/web/basic-component-sevice/pay?token=' + localStorage.getItem('token')
wrapstringiframe放置的元素#pay-iframe
targetOriginstring
tokenstringlocalStorage.getItem('token')
1.0.19

1 year ago

1.0.18

1 year ago

1.0.20

1 year ago

1.0.17

2 years ago

1.0.16

2 years ago

1.0.9

2 years ago

1.0.8

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.11

2 years ago

1.0.10

2 years ago

1.0.15

2 years ago

1.0.14

2 years ago

1.0.13

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago