跳到主要内容
版本:3.x

WebView

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

支持情况:

参考文档

类型

ComponentType<WebViewProps>

示例代码

class App extends Component {
handleMessage () {}

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

WebViewProps

参数类型默认值必填说明
srcstringwebview 指向网页的链接。可打开关联的公众号的文章,其它网页需登录小程序管理后台配置业务域名。
progressbarColorstringwebview 的进度条颜色
typestringdefault若使用web-view组件引入第三方客服,必须填写type="im"
onMessageCommonEventFunction<onMessageEventDetail>网页向小程序 postMessage 时,会在特定时机(小程序后退、组件销毁、分享)触发并收到消息。e.detail = { data }
onLoadCommonEventFunction<onLoadEventDetail>网页加载成功时候触发此事件。e.detail = { src }
onErrorCommonEventFunction<onErrorEventDetail>网页加载失败的时候触发此事件。e.detail = { src }

API 支持度

API微信小程序百度小程序支付宝小程序抖音小程序QQ 小程序京东小程序H5React NativeHarmony
WebViewProps.src✔️✔️✔️✔️✔️✔️✔️✔️
WebViewProps.progressbarColor✔️
WebViewProps.type✔️
WebViewProps.onMessage✔️✔️✔️✔️✔️✔️
WebViewProps.onLoad✔️✔️✔️✔️✔️✔️
WebViewProps.onError✔️✔️✔️✔️✔️✔️

onMessageEventDetail

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

onLoadEventDetail

参数类型说明
srcstring网页链接

onErrorEventDetail

参数类型说明
srcstring网页链接