Skip to content

iframe

介绍

iframe 组件允许将外部页面嵌入到当前页面中。

API

Props

参数名描述类型默认值
url地址。指定要嵌入的网页地址string-
autoHeight自定义高度。嵌入内容在页面中的显示高度booleanfalse
baseStyle自定义样式string-
customClass类名绑定string-
opacity不透明度 , 布局容器背景色透明度string-
display显示,设置组件的显示布局模式Display-
boxStyle盒模型 , margin,border,padding 设置BoxStyle-
background背景样式Background-
boxShadow阴影BoxShadow-
uniqueKey唯一标识 , 组件的唯一标识string-
loop循环数据 , 循环渲染设置Loop-

Events

事件名描述参数
onIframeLoadediframe 挂载完成后调用ctx:PangeaContext

注意:

如需触发onIframeLoaded事件,需在嵌入页面中执行window.parent.postMessage("onIframeLoaded","*")

Methods


方法名描述参数返回值
postMessage主动向嵌入页面发送数据any-

Type

javascript
//样式-显示
type Display = {
  type:"block"|"inline-block"|"inline"|"flex",
  // type选择flex可配置以下属性
  flex:{
    flexDirection:"row"|"column"|"row-reverse"|"column-reverse",
    alignItems:"flex-start"|"center"|"flex-end"|"stretch"|"base-line",
    justifyContent:"flex-start"|"center"|"flex-end"|"space-between"|"space-around"
  }
}

// 盒模型
type BoxStyle = {
  "marigin": [string|string|string|string],
  "border": [string|string|string|string],
  "padding": [string|string|string|string],
}

// 背景样式
type Background = {
  "color": string,
  "size": "cover"|"contain"|"length"
  "width": {
    "unit": "px"|"%",
    "value": number
  }
  "height":{
    "unit": "px"|"%",
    "value": number
  }
}

// 阴影
type BoxShadow = {
  "color":string,
  "hShadow":string,
  "vShadow":string,
  "blur":number,
}

// 循环
type Loop = {
  "data": any[],
  "paramName": string,
  "indexName": string,
  "key": string
}

// 循环变量数据参数
type LoopParams = {
  "indexName":string,
  "paramName":string,
  "ref":ComputedRefImpl, // 全部的循环变量数据
  "row":any,
  "rowIndex":number
}[]

常见场景配置

向嵌入页面发送数据

  1. iframe挂载完成后调用事件中,执行以下方法:
js
ctx.triggerEvent(key, "postmessage", data);

其中keyiframe组件的唯一标识,data为要发送的数据。

  1. 在接收数据的页面中,执行以下方法接收数据:
js
window.parent.postMessage("onIframeLoaded", "*");
window.addEventListener("message", function (event) {});

其中event为接收的的数据。