Skip to main content
Version: 下个版本

WebView

web-view 组件是一个可以用来承载网页的容器,会自动铺满整个小程序页面。个人类型与海外类型的小程序暂不支持使用。

支持情况:

参考文档

类型

ComponentType<WebViewProps>

示例代码

class App extends Component {
handleMessage () {}

render () {
return (
<WebView src='https://mp.weixin.qq.com/' onMessage={this.handleMessage} />
)
}
}

WebViewProps

参数类型必填说明
srcstringwebview 指向网页的链接。可打开关联的公众号的文章,其它网页需登录小程序管理后台配置业务域名。
onMessageCommonEventFunction<onMessageEventDetail>网页向小程序 postMessage 时,会在特定时机(小程序后退、组件销毁、分享)触发并收到消息。e.detail = { data }
onLoadCommonEventFunction<onLoadEventDetail>网页加载成功时候触发此事件。e.detail = { src }
onErrorCommonEventFunction<onErrorEventDetail>网页加载失败的时候触发此事件。e.detail = { src }

API 支持度

API微信小程序H5React Native
WebViewProps.src✔️✔️
WebViewProps.onMessage✔️
WebViewProps.onLoad✔️✔️
WebViewProps.onError✔️✔️

onMessageEventDetail

参数类型说明
dataany[]消息数据,是多次 postMessage 的参数组成的数组

onLoadEventDetail

参数类型说明
srcstring网页链接

onErrorEventDetail

参数类型说明
srcstring网页链接