UNPKG

2.02 kBTypeScriptView Raw
1import { ComponentType } from 'react'
2import { StandardProps, CommonEventFunction } from './common'
3
4interface WebViewProps extends StandardProps {
5 /** webview 指向网页的链接。可打开关联的公众号的文章,其它网页需登录小程序管理后台配置业务域名。
6 * @supported weapp, h5, rn, tt
7 */
8 src: string
9
10 /** 网页向小程序 postMessage 时,会在特定时机(小程序后退、组件销毁、分享)触发并收到消息。e.detail = { data }
11 * @supported weapp, tt
12 */
13 onMessage?: CommonEventFunction<WebViewProps.onMessageEventDetail>
14
15 /** 网页加载成功时候触发此事件。e.detail = { src }
16 * @supported weapp, h5, rn, tt
17 */
18 onLoad?: CommonEventFunction<WebViewProps.onLoadEventDetail>
19
20 /** 网页加载失败的时候触发此事件。e.detail = { src }
21 * @supported weapp, h5, rn, tt
22 */
23 onError?: CommonEventFunction<WebViewProps.onErrorEventDetail>
24}
25
26declare namespace WebViewProps {
27 interface onMessageEventDetail {
28 /** 消息数据,是多次 postMessage 的参数组成的数组 */
29 data: any[]
30 }
31 interface onLoadEventDetail {
32 /** 网页链接 */
33 src: string
34 }
35 interface onErrorEventDetail {
36 /** 网页链接 */
37 src: string
38 }
39}
40
41/** web-view 组件是一个可以用来承载网页的容器,会自动铺满整个小程序页面。个人类型与海外类型的小程序暂不支持使用。
42 * @classification open
43 * @supported weapp, h5, rn, tt
44 * @example_react
45 * ```tsx
46 * class App extends Component {
47 * handleMessage () {}
48 *
49 * render () {
50 * return (
51 * <WebView src='https://mp.weixin.qq.com/' onMessage={this.handleMessage} />
52 * )
53 * }
54 * }
55 * ```
56 * @example_vue
57 * ```html
58 * <template>
59 * <web-view src='https://mp.weixin.qq.com/' `@message="handleMessage" />
60 * </template>
61 * ```
62 * @see https://developers.weixin.qq.com/miniprogram/dev/component/web-view.html
63 */
64declare const WebView: ComponentType<WebViewProps>
65
66export { WebView, WebViewProps }